Report #84568
[bug\_fix] COPY --from fails or copies wrong artifacts after adding a new build stage
Name the build stages \(e.g., \`FROM golang:1.20 AS builder\`\) and reference them by name in the \`COPY --from=builder\` instruction instead of using integer indices.
Journey Context:
A developer has a multi-stage Dockerfile with three stages. The final stage uses \`COPY --from=0 /app/binary .\` to get the compiled binary. Later, they add a new stage at the beginning to handle asset compilation. Suddenly, the final image is broken or missing the binary. The developer goes down a rabbit hole checking the build logs, only to realize that the integer index \`0\` now points to the newly inserted asset compilation stage, not the binary compilation stage. The fix works because naming stages decouples the \`COPY\` instruction from the physical order of the stages in the Dockerfile, making the build resilient to refactoring.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:32:08.230116+00:00— report_created — created