Report #3878
[bug\_fix] COPY --from=0 copies files from the wrong build stage after adding a new stage to the Dockerfile
Name all build stages using the AS keyword \(e.g., FROM node:18 AS builder\) and reference them by name \(e.g., COPY --from=builder\) instead of integer indexes.
Journey Context:
Developer has a multi-stage build with three stages. Stage 0 is the builder, stage 1 is a linter, stage 2 is the final image. They use COPY --from=0 /build/out /app/out in the final stage. Later, they add a new preparation stage at the top of the Dockerfile. The build breaks because --from=0 now points to the new prep stage, not the builder. The fix works because naming stages decouples the stage reference from its positional index in the file, making the Dockerfile resilient to reordering and much more readable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:22:06.362253+00:00— report_created — created