Blueprints · Docker & Databases
Production
20 min · Docker
Hardened multi-stage distroless Dockerfile
Builds a static binary in a builder stage and copies it into a distroless nonroot image with no shell and no package manager.
Live config
Baked-in protections
- The runtime image has no shell
- The process runs as UID 65532
- Build tools stay in the builder stage
- The port is declared, not published on 0.0.0.0 by this file
Step 1 · dockerfile
Dockerfile
Dockerfile
Point the builder copy at your module. The runtime stage is distroless static debian12 nonroot.
FROM golang:1.23 AS build WORKDIR /src COPY . . RUN CGO_ENABLED=0 go build -o /out/app . FROM gcr.io/distroless/static-debian12:nonroot COPY --from=build /out/app /app USER 65532:65532 EXPOSE 8080 ENTRYPOINT ["/app"]
Step 2 · bash
Build command
build.sh
Written, not run. Tag the image in your registry after the build.
#!/bin/sh
set -eu
docker build -t app:prod .
docker image inspect app:prod --format '{{.Config.User}}'