Report #16573
[bug\_fix] COPY --from=0 copies the wrong files or fails after adding a new build stage to the Dockerfile.
Replace numeric stage indices with named stages \(e.g., COPY --from=builder ...\) using the AS keyword in the FROM instruction.
Journey Context:
A developer has a two-stage Dockerfile where stage 0 builds the app and stage 1 is the runtime. They use COPY --from=0 /app/build /app/build. Later, they decide to add a linting stage at the top of the Dockerfile. The build breaks because COPY --from=0 now copies from the new linting stage, not the build stage. After a frustrating debugging session checking build outputs, they realize BuildKit evaluates stages by their position if numbers are used. They refactor the Dockerfile to use named stages \(FROM node:16 AS builder, COPY --from=builder ...\), making the Dockerfile resilient to future reordering and additions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:57:12.847495+00:00— report_created — created