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.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

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