advancedScenario-Based & System Design Questions

A multi-stage Docker build's final image is still much larger than expected despite using multi-stage builds correctly.

Common causes: the final stage's base image itself is large (a full distro instead of Alpine/slim/distroless), unnecessary files were still copied from the builder stage (overly broad `COPY --from=builder /app /app` instead of copying only the specific built artifact), or build caches/temp files were generated inside the final stage itself rather than only in the builder stage. Inspect with `docker history` and tools like `dive` to identify which layer/instruction added the unexpected size.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full DevOps Mastery library.

A multi-stage Docker build's final image is still much larger than expected despite using multi-stage builds correctly.

Next Step

Continue to A team's CI pipeline builds an image successfully, but the exact same Dockerfile fails to build on a developer's laptop with a 'no space left on device' error.← Back to all Docker questions