Skip to content

Instantly share code, notes, and snippets.

@MatthewJamesBoyle
Last active March 11, 2024 15:57
Show Gist options
  • Save MatthewJamesBoyle/598538dd1c8d38f9dc70575b1be5958a to your computer and use it in GitHub Desktop.
Save MatthewJamesBoyle/598538dd1c8d38f9dc70575b1be5958a to your computer and use it in GitHub Desktop.
production go dockerfile
FROM golang:1.21.0-bullseye as builder
COPY . /workdir
WORKDIR /workdir
ENV CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-all"
ENV GOFLAGS="-buildmode=pie"
RUN go build -ldflags "-s -w" -trimpath ./cmd/app
FROM gcr.io/distroless/base-debian11:nonroot
COPY --from=builder /workdir/app /bin/app
USER 65534
ENTRYPOINT ["/bin/app"]
@m4salah
Copy link

m4salah commented Aug 11, 2023

Why not using gcr.io/distroless/static-debian11.
I got from 34 MB using gcr.io/distroless/base-debian11 to 16 MB using gcr.io/distroless/static-debian11

@mqssi
Copy link

mqssi commented Aug 14, 2023

Could be because of CGO dependencies of the app

https://iximiuz.com/en/posts/containers-distroless-images/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment