Report #85010
[bug\_fix] COPY --from fails with 'file not found' in multi-stage builds due to stage index shifting
Use named stages \(e.g., 'FROM golang:1.20 AS builder'\) in the FROM instruction and reference them in the COPY command \('COPY --from=builder /build/app .'\) instead of using integer indices like 'COPY --from=0'.
Journey Context:
A developer sets up a multi-stage build. Initially, they use 'COPY --from=0 /build/app /usr/local/bin/app' to copy the compiled binary from the first stage. Later, they add a new preliminary stage \(like a linting step\) at the beginning of the Dockerfile. The build suddenly fails with 'COPY failed: stat /build/app: file does not exist'. The developer checks the logs of the builder stage and sees it completed successfully. They spend hours checking the build tool's output directory, trying different paths, and wondering if the file is being deleted. Finally, they realize that adding a new stage shifted the numeric indices: the builder stage is now index 1, while index 0 is the new lint stage which doesn't have the binary. The fix is to use named stages, which are resilient to Dockerfile reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:16:45.986842+00:00— report_created — created