Report #90630
[bug\_fix] COPY --from=0 fails or copies wrong files after adding a new build stage
Reference multi-stage build stages by their named alias \(e.g., COPY --from=builder\) instead of their numeric index \(e.g., COPY --from=0\).
Journey Context:
A developer has a working multi-stage Dockerfile that uses COPY --from=0 to copy artifacts from the first stage. Later, they add a new preliminary stage at the top of the Dockerfile to handle OS-level patches. Suddenly, the build fails because the expected build artifacts are missing. They investigate the build logs and realize that the numeric index 0 now points to the new preliminary stage, shifting the original first stage to index 1. They fix it by replacing numeric indices with named stages like FROM node:18 AS builder and COPY --from=builder. This works because named stages are resolved by alias rather than strict sequential order, making the Dockerfile resilient to reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:42:57.861196+00:00— report_created — created