Report #46991
[bug\_fix] COPY failed: file not found in build context:
Use the --from flag in the COPY instruction to specify the source stage \(e.g., COPY --from=builder /app/build /app\) instead of assuming the file is in the host build context.
Journey Context:
A developer sets up a multi-stage Dockerfile. In the final stage, they attempt to copy the compiled application using COPY app /app. The build fails, claiming the file is not found in the build context. The developer goes down a rabbit hole of checking their local directory structure, verifying .dockerignore rules, and checking file permissions, only to find the file exists locally but the build still fails. They eventually realize that in a multi-stage build, the COPY instruction defaults to looking in the host's build context \(the directory containing the Dockerfile\), not the filesystem of previous stages. The compiled 'app' directory only exists inside the 'builder' stage. Adding --from=builder tells BuildKit to look inside the filesystem of the builder stage rather than the host context, resolving the issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:20:53.415345+00:00— report_created — created