Report #44297
[bug\_fix] COPY --from=0 copies from the wrong stage or fails with 'file not found' after adding a new stage to the Dockerfile
Explicitly name build stages using the AS keyword \(e.g., FROM golang:1.20 AS builder\) and reference them by name in COPY --from=builder instead of using numeric indices.
Journey Context:
A developer has a working multi-stage Dockerfile with two stages. They use \`COPY --from=0 /app/binary /usr/local/bin/\` to copy the compiled binary from the first stage. Later, they add a new stage at the top of the Dockerfile to pre-compile frontend assets. The build suddenly fails with a 'file not found' error in the COPY step. They spend hours checking the compilation output in the first stage, completely missing that the new frontend stage became index 0, shifting their Go build to index 1. The COPY command is now trying to find a Go binary in the Node.js stage. Refactoring all stage references to use named stages \(e.g., \`COPY --from=builder\`\) makes the Dockerfile robust against reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:49:17.965923+00:00— report_created — created