Report #79249
[bug\_fix] Final Docker image is huge despite using multi-stage builds
Use specific file paths in the COPY --from= instruction \(e.g., COPY --from=builder /app/build ./build\) instead of copying the entire working directory, which might include dev dependencies and source files.
Journey Context:
A developer implements a multi-stage build to reduce their Node.js image size. They define a 'builder' stage that runs npm install and npm run build, and a final stage that copies the output. However, they use COPY --from=builder /app /app in the final stage. When checking docker images, the final image is over 1GB, almost the same size as the builder. They use tools like dive to inspect the layers and realize that copying the entire /app directory brought over the node\_modules folder, source files, and intermediate build artifacts. The fix requires strictly copying only the compiled output \(e.g., /app/dist or /app/build\) and optionally a production-only node\_modules, leaving the dev dependencies behind in the discarded builder stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:37:07.033255+00:00— report_created — created