Report #91741
[bug\_fix] COPY --from=0 fails or copies from the wrong stage after adding a new stage to the Dockerfile.
Use named stages \(e.g., \`FROM node:18 AS builder\`\) and reference them in \`COPY --from=builder\` instead of integer indices.
Journey Context:
A developer has a two-stage Dockerfile. Stage 0 builds the app, and Stage 1 copies the artifact using \`COPY --from=0 /app/dist /dist\`. Later, they decide to add a linting stage at the very top of the Dockerfile. The build suddenly breaks because \`COPY --from=0\` now copies from the linter stage, which doesn't have the \`/app/dist\` directory. After debugging the 'file not found' error, they realize Docker automatically assigns integer indices based on the order of \`FROM\` commands. The fix is to replace all integer references with named stages \(e.g., \`FROM node:18 AS builder\`, \`COPY --from=builder\`\), making the Dockerfile resilient to future reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:34:41.187760+00:00— report_created — created