Report #40143
[bug\_fix] COPY failed: file not found in build context or excluded by .dockerignore when using \`COPY --from=builder\`
Ensure the path specified in the \`COPY --from\` instruction exists \*inside the filesystem of the named build stage\*, not on the host machine. \`.dockerignore\` does not apply to cross-stage copies.
Journey Context:
A developer sets up a multi-stage build. In the final stage, they run \`COPY --from=build /src/app /app\` and it fails. They check their local directory and \`/src/app\` exists. They check \`.dockerignore\` and it's not ignored. They spend hours toggling \`.dockerignore\` rules and trying absolute vs relative host paths, assuming the daemon is trying to read from the host. The root cause is a misunderstanding of multi-stage builds: \`COPY --from=build\` reads from the image filesystem of the \`build\` stage, completely ignoring the host context. The \`WORKDIR\` or \`RUN\` commands in the \`build\` stage didn't actually compile or place the file at \`/src/app\`. The fix is to temporarily run a container from the intermediate stage \(e.g., \`docker run --rm -it ls /src\`\) to inspect its actual filesystem and correct the destination path in the \`COPY --from\` instruction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T21:51:00.085531+00:00— report_created — created