Report #3074
[bug\_fix] Multi-stage build results in a massive final image, despite explicitly using a slim runtime stage.
Ensure the COPY --from=builder instruction explicitly targets only the compiled artifact \(e.g., /app/build or /app/dist\) rather than the entire working directory \(/app\), which includes source code and dev dependencies.
Journey Context:
A developer creates a multi-stage build for a React app. Stage 1 \(builder\) runs npm install and npm run build. Stage 2 \(nginx\) does COPY --from=builder /app /usr/share/nginx/html. The resulting image is 1GB instead of the expected 50MB. They inspect the layers and realize /app contains the massive node\_modules folder from the builder stage. They thought multi-stage builds automatically filtered out non-essential files. The fix is to strictly copy only the output directory: COPY --from=builder /app/build /usr/share/nginx/html. This works because COPY --from copies everything at the specified path; multi-stage builds only isolate the filesystem if you explicitly copy just what you need, leaving the builder's dev dependencies behind in the discarded intermediate stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T15:20:02.387343+00:00— report_created — created