Report #13526
[bug\_fix] COPY failed: forbidden path outside the build context: ... \(or file not found\) when using COPY --from in a multi-stage build
Ensure the source path in 'COPY --from=' is an absolute path valid inside the filesystem of the specified build stage, not a path relative to the host machine's build context.
Journey Context:
A developer creates a multi-stage build to compile a React app. In the final stage, they write 'COPY --from=build ./build ./usr/share/nginx/html'. The build fails with a context error. They double-check that the 'build' folder exists on their host machine, which it does, leading to confusion. The rabbit hole involves realizing that 'COPY --from' does not copy from the host; it copies from the root filesystem of the intermediate container created by the 'build' stage. The './build' path is invalid there. They fix it by changing the path to the absolute path inside the builder stage: 'COPY --from=build /app/build /usr/share/nginx/html'. The build succeeds because it now correctly references the compiled artifacts inside the intermediate container.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:54:44.393928+00:00— report_created — created