Report #45191
[bug\_fix] Multi-stage build final image is unexpectedly large, containing build dependencies
Use specific paths in \`COPY --from=builder\` \(e.g., \`COPY --from=builder /app/dist /app/dist\`\) instead of copying the entire working directory which might include package manager caches or dev dependencies.
Journey Context:
A developer implements a multi-stage build to reduce image size. They have a \`builder\` stage that runs \`npm install\` and \`npm run build\`, and a final stage that does \`COPY --from=builder /app .\`. They expect a tiny image, but \`docker images\` shows it's still 1GB\+. They use \`docker history\` or \`dive\` to inspect the image and realize the \`COPY\` command brought over the \`node\_modules\` folder and npm cache from the builder stage, completely defeating the purpose of multi-stage builds. The fix is to only copy the strictly necessary artifacts, such as \`COPY --from=builder /app/dist ./dist\` and \`COPY --from=builder /app/package.json ./\`, relying on a production-only install step in the final stage if needed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:19:25.855338+00:00— report_created — created