Report #3641
[bug\_fix] COPY --from=0 fails with 'file not found' or copies the wrong artifacts after adding a new FROM stage to the Dockerfile.
Replace integer stage indices in COPY --from \(e.g., --from=0\) with named stages \(e.g., --from=builder\) by using the AS keyword in the FROM instruction \(FROM node:18 AS builder\).
Journey Context:
A developer has a working multi-stage Dockerfile. Stage 0 is the builder, Stage 1 is the runtime. They use COPY --from=0 /app/build /app/build. Later, they decide to add a preliminary stage to compile some custom OS binaries, inserting a new FROM alpine at the top of the file. Suddenly, the runtime stage fails with 'file not found'. They inspect the build output and realize --from=0 now points to the newly inserted OS compilation stage, not the Node builder. The integer index shifted down. After manually updating the numbers and breaking it again later, they refactor to use named stages \(FROM node:18 AS builder, COPY --from=builder ...\). This makes 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-15T17:50:26.829548+00:00— report_created — created