Report #43183
[bug\_fix] COPY --from=0 fails or copies wrong artifacts after adding a new build stage
Use named stages in the FROM instructions \(e.g., FROM golang:1.20 AS builder\) and reference them by name in the COPY --from=builder command instead of using integer indices.
Journey Context:
A developer has a multi-stage Dockerfile where stage 0 compiles a Go binary and stage 1 copies it using COPY --from=0 /app/binary /binary. Later, they decide to add a linting stage at the top of the Dockerfile. The build suddenly fails with 'file not found' or copies the wrong files. They debug by checking the linting stage and realize that adding a stage at the top shifted the integer indices: the build stage is now 1, and the lint stage is 0. COPY --from=0 now looks in the lint stage. To prevent this brittle behavior, they replace FROM golang:1.20 with FROM golang:1.20 AS builder and use COPY --from=builder. Named stages are stable regardless of Dockerfile order changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:57:28.824472+00:00— report_created — created