Report #17834
[bug\_fix] COPY failed: stat /path/to/file: file does not exist when using COPY --from=builder in a multi-stage build.
Ensure the source path in \`COPY --from=builder \` is either an absolute path from the root of the builder stage's filesystem, or correctly relative to the builder stage's last \`WORKDIR\`.
Journey Context:
A developer sets up a multi-stage build. In the builder stage, they set \`WORKDIR /app\` and compile their application, outputting the binary to \`./build/app.bin\` \(which resolves to \`/app/build/app.bin\`\). In the final stage, they attempt to copy it using \`COPY --from=builder build/app.bin /usr/local/bin/\`. The build fails, claiming the file does not exist. The developer assumes the build step failed silently and adds \`ls -R\` to the builder stage, confirming the file is there. The rabbit hole involves trying different relative paths, assuming \`COPY --from\` resolves relative to the current stage's workdir. The actual root cause is that \`COPY --from\` resolves the source path relative to the source stage's \`WORKDIR\`. Since the builder's workdir is \`/app\`, \`build/app.bin\` works, but if they had changed the workdir in the final stage, it would not affect the source resolution. Using absolute paths like \`COPY --from=builder /app/build/app.bin /usr/local/bin/\` removes all ambiguity and reliably copies the artifact.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:27:28.356055+00:00— report_created — created