What is a multi-stage build?
BeginnerConceptDockerfile Instructions & Builds
Answer
A Dockerfile with several FROM stages where later stages copy artifacts from earlier ones with COPY --from=<stage>. Compilers and build tools stay in the builder stage and only the runtime output ships, producing much smaller, safer images.
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/api
FROM gcr.io/distroless/static-debian12
COPY --from=build /app /app
ENTRYPOINT ["/app"]