Report #24973
[bug\_fix] COPY failed: file not found in build context: stat : file does not exist
Add the --from= flag to the COPY instruction to explicitly copy from a previous build stage instead of the build context \(e.g., COPY --from=builder /app/build /usr/local/bin\).
Journey Context:
A developer sets up a multi-stage build. In stage 1, named 'builder', they compile a binary to /app/build/output. In stage 2, they write COPY /app/build/output /usr/local/bin/. Docker immediately throws 'file not found in build context'. They are confused because they know the file was just created in the previous step. They check the path, the spelling, and the build context, finding nothing wrong. The breakthrough comes when they realize the error specifically says 'build context'. By default, the COPY instruction only looks at the host's build context \(the directory passed to docker build\), not the filesystem of previous stages. The fix is to add --from=builder to the COPY command. This explicitly tells BuildKit to resolve the source path from the filesystem of the 'builder' stage rather than the host context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:19:36.130698+00:00— report_created — created