Report #11297
[bug\_fix] COPY --from fails with missing files or wrong stage binaries in multi-stage builds
Use explicit stage aliases \(\`FROM ... AS builder\`\) and reference them by name in \`COPY --from=builder\` instead of using integer indices \(\`COPY --from=0\`\). Ensure the copied path matches the exact directory structure created in the named stage.
Journey Context:
A developer has a multi-stage build. They add a new stage at the beginning to compile a native C dependency, shifting the integer indices of subsequent stages. The build succeeds, but the final image crashes with \`executable file not found\`. They debug by checking the build logs and seeing the binary was built in stage 1, but \`COPY --from=1 /app/binary /\` is now copying from the newly inserted C stage, not the Go build stage. They spend hours checking the Go compilation flags, thinking the binary is corrupted. The root cause is relying on fragile integer indices. The fix is to explicitly name stages \(\`FROM golang:1.20 AS builder\`\) and use \`COPY --from=builder /app/binary /\`. This makes the Dockerfile resilient to stage reordering and clearly documents the source of the artifact.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:55:21.900800+00:00— report_created — created