Report #88303
[bug\_fix] COPY --from=0 copies the wrong artifacts or fails after adding a new stage to a multi-stage 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 multi-stage Dockerfile with three stages. They use \`COPY --from=0 /app/build ./build\` to copy the compiled output from the first stage. Later, they add a new stage at the beginning of the Dockerfile for preparing dependencies. The build suddenly fails or produces an empty \`./build\` directory. The developer is baffled because the build logs show the compiler ran successfully. They realize that adding a stage at the top shifted all the integer indices, so \`--from=0\` now points to the new dependency stage, not the builder stage. By refactoring to use named stages \(\`FROM node:18 AS builder\` and \`COPY --from=builder\`\), the reference becomes resilient to Dockerfile modifications, completely avoiding the index shifting pitfall.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:48:09.723203+00:00— report_created — created