Report #4719
[bug\_fix] COPY --from=0 fails or copies wrong files in multi-stage builds
Use named stages \(e.g., FROM node:18 AS builder\) and reference them by name \(COPY --from=builder\) instead of using integer indices, and verify the absolute path of the artifact in the source stage.
Journey Context:
A developer sets up a multi-stage build. Stage 0 compiles an asset, and Stage 1 tries to 'COPY --from=0 /build/output /app/'. It fails with 'file not found'. They debug by running a temporary container from the builder stage \('docker run --rm -it sh'\) and listing files, only to realize the build tool wrote to '/opt/build/output' instead of '/build/output'. After fixing the path, they later add a new stage at the beginning of the Dockerfile, which shifts the indices, causing 'COPY --from=0' to pull from the wrong stage entirely. The fix is twofold: always use named stages like 'FROM golang:1.20 AS builder' and 'COPY --from=builder /opt/build/output /app/' to make the Dockerfile resilient to reordering, and always double-check the absolute paths inside the intermediate stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:57:41.785748+00:00— report_created — created