Interview Prep/Docker/Image design and Dockerfile decisions

You need a tiny static Go binary in production. Which base image do you choose?

IntermediateScenarioImage design and Dockerfile decisions
Answer

Situation read → Static binaries do not need a libc or a package manager.

What I'd do →

FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/app ./cmd/app

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]

scratch works too but lacks CA certificates and /etc/passwd; distroless static includes both.

Why → Minimal attack surface, a few MB image.

Interview tip → Mention you lose a shell; use docker debug or an ephemeral debug container.

All Docker questions Roadmap: Docker & containers

More on Image design and Dockerfile decisions