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.
More on Image design and Dockerfile decisions
A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?BeginnerYou need to run `apt-get install` in a Dockerfile. How do you write it so the layer stays small and cache-safe?BeginnerWhen would you pick `COPY` over `ADD`?BeginnerA service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?BeginnerYour Docker build re-installs all Python dependencies on every code change. Fix it.BeginnerProduct asks for a container that runs both nginx and a Python app. What do you say?Beginner