Report #40673
[bug\_fix] COPY --from=0 fails with 'file not found' in multi-stage builds despite the build succeeding in the previous stage
Name the build stages \(e.g., FROM node:14 AS builder\) instead of relying on implicit numbering, and verify the absolute path where the previous stage wrote the files. Remember that WORKDIR changes the path context for subsequent COPY commands.
Journey Context:
A developer creates a multi-stage build. Stage 0 compiles an app into a dist/ folder. Stage 1 tries to COPY --from=0 /src/dist /app/ but fails with file not found. They add an ls in stage 0 and see the files are there. They try relative paths, absolute paths, and different stage numbers. The issue is they used WORKDIR /build in stage 0, so the files were actually written to /build/dist, not /src/dist. By naming the stage AS builder and using COPY --from=builder /build/dist /app/, they resolve the path confusion. The fix works because naming stages prevents fragile implicit numbering errors, and using the correct absolute path respects the WORKDIR instruction of the source stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:44:30.251740+00:00— report_created — created