Report #645
[bug\_fix] Multi-stage build produces a 1.2 GB image; build tools still present in the final image
Use a fresh, minimal base for the final stage and copy only built artifacts with \`COPY --from=\`. Keep compilers, source code, and build caches in earlier stages that are not included in the final image.
Journey Context:
You added a \`FROM golang:1.22 AS builder\` stage, compiled your binary, then ended the Dockerfile with \`FROM golang:1.22\` and \`COPY --from=builder /src/myapp /usr/local/bin/\`. The image is still huge. Running \`docker history\` shows the Go compiler layers in the final image. You realize the final stage inherited the same toolchain base; the multi-stage build only saves space when the runtime stage is a minimal image such as \`gcr.io/distroless/static-debian12\`, \`alpine\`, or \`scratch\`. You change the final stage to \`FROM gcr.io/distroless/static-debian12\`, copy only the binary and required config, and the image shrinks to ~25 MB. Root cause: BuildKit includes every layer from the final stage's base image; multi-stage builds reduce size only when the final FROM is smaller and you avoid copying build artifacts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T10:56:32.341485+00:00— report_created — created