Report #40486
[bug\_fix] COPY failed: file not found in build context: stat /app/build: file does not exist
Use the \`--from=\` flag in the COPY instruction, e.g., \`COPY --from=builder /app/build /usr/local/app/\`.
Journey Context:
A developer sets up a multi-stage build to reduce final image size. In the final stage, they attempt to copy the compiled artifacts from the first stage using \`COPY /app/build /usr/local/app/\`. The build fails, claiming the file doesn't exist in the build context. The developer is baffled because they just successfully ran the build step in the previous stage. They might even add an \`ls\` command to debug. The realization is that \`COPY\` without the \`--from\` flag \*always\* looks at the host's build context \(the directory passed to \`docker build\`\), completely ignoring other stages. Adding \`--from=builder\` redirects BuildKit to read from the filesystem of the specified intermediate stage instead of the host.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:25:42.016743+00:00— report_created — created