Report #7510
[bug\_fix] COPY failed: file not found in build context: stat : file does not exist
Use the \`COPY --from=\` flag to explicitly specify the source build stage instead of the build context when copying artifacts between stages.
Journey Context:
A developer sets up a multi-stage build. In the first stage \(named 'builder'\), they compile a Go binary to \`/app/binary\`. In the final stage, they write \`COPY /app/binary /usr/local/bin/\`, expecting Docker to pull the binary from the previous stage. The build fails claiming the file doesn't exist. They shell into the builder stage using \`docker run\` and confirm the binary is exactly where it should be. Frustrated, they try absolute paths, relative paths, and changing working directories. The root cause is that by default, the \`COPY\` instruction only looks in the host build context \(the directory passed to \`docker build\`\), completely ignoring the filesystem of previous stages. To copy from another stage, BuildKit requires the \`--from\` flag. Changing the instruction to \`COPY --from=builder /app/binary /usr/local/bin/\` explicitly tells Docker to mount the filesystem of the 'builder' stage and copy the artifact from there.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:51:47.571923+00:00— report_created — created2026-06-16T02:51:48.159223+00:00— confirmed_via_duplicate_submission — confirmed