Report #11493
[bug\_fix] COPY failed: stat : file does not exist when using \`COPY --from=\` in a multi-stage build.
Use named stages \(e.g., \`FROM golang:1.20 AS builder\`\) instead of integer indices \(e.g., \`COPY --from=0\`\) to prevent off-by-one errors when adding or removing build stages.
Journey Context:
A developer has a multi-stage Dockerfile. Stage 0 compiles a Go binary, Stage 1 does something else, Stage 2 is the final slim image. They use \`COPY --from=0 /app/binary /app/binary\`. Later, they insert a new stage at the beginning to generate some assets, pushing the Go build to Stage 1. The build breaks because \`COPY --from=0\` now points to the asset generation stage, which doesn't have the Go binary. The developer spends hours trying to figure out why the binary isn't being built, only to realize the stage index shifted. They fix it by giving the Go stage a name \(\`AS builder\`\) and using \`COPY --from=builder\`, which is resilient to stage reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:24:51.852668+00:00— report_created — created