Use latest version of golang as builder container
FROM golang:1.21-alpine as builder
Set workdir to /app
WORKDIR /app
Copy files from current dir to /app/*
COPY . .
Download mods
RUN go mod download
Build go app in build container
RUN CGO_ENABLED=0 go build -o /my-app
Use as small container as possible
FROM scratch
Copy root SSL sertificates to production container
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Copy our app from build container to production container
COPY --from=builder /my-app /my-app
Set entrypoint
ENTRYPOINT ["/my-app"]
to build our app run
docker build -t goapp .
and run it
docker run --rm -it goapp
Top comments (0)