A multi-stage build copies from `--from=build` but the final image is still huge. Why?
IntermediateScenarioMulti-stage builds, cache, tags and registries
Answer
Situation read → Probably copying a whole directory (COPY --from=build /src /app) including node_modules dev deps or source, or the final stage is built FROM build.
What I'd do →
docker history appto find the heavy layer.- Copy only artifacts (
/src/dist, the binary). - Install prod-only deps in the final stage or prune (
npm prune --omit=dev). - Verify with
dive.
Why → Multi-stage only helps if the last stage starts from a clean base.
Interview tip → Check that the last FROM is the slim runtime image.
More on Multi-stage builds, cache, tags and registries
Show a multi-stage Dockerfile for a Java Spring Boot app and explain what you gain.BeginnerCI rebuilds from scratch every run and takes 12 minutes. How do you bring it down?IntermediateYou tag every build `myapp:latest`. A rollback is requested. What happens?BeginnerHow do you promote an image from dev to prod registry without rebuilding?IntermediateDisk on the build server keeps filling up with images.BeginnerWhen do you use `--no-cache` and when is it a smell?Beginner