Go app deployment with Dockerfile
# Builder
FROM golang:latest AS builder
WORKDIR /app
# download the dependencies dependencies first so that they can be cached.
COPY go.mod go.sum./
RUN go mod download
# copy the source code and build the go app
COPY..
RUN go build -o main.
# Runner
FROM alpine:latest
WORKDIR /root
COPY /app/main.
# download the tool needed to run the app
RUN apk update
RUN apk add libc6-compat
EXPOSE $PORT
CMD ["/root/main"]
Caution
Remember to install libc6-compat other wise your container may not issue CMD successfully
In your Dockerfile:
RUN apk update
RUN apk add libc6-compat