Report #961
[bug\_fix] Multi-stage COPY --from fails with stage name or index not found
Reference the stage exactly as declared in the FROM instruction. If the stage has an alias \(\`FROM golang:1.21 AS builder\`\), use that alias in \`COPY --from=builder\`. If you reference a previous stage by index, use 0-based numbering matching the order of FROM declarations, and ensure the stage is not skipped by a conditional build.
Journey Context:
You add a multi-stage build to shrink your image: a builder stage compiles a binary, then \`FROM scratch\` and \`COPY --from=builder /app/bin /bin\`. The build fails saying \`stage builder not found\` even though \`FROM golang:1.21 AS builder\` is in the file. You check spelling, case sensitivity, and even try \`COPY --from=0\`. Then you realize you wrote \`FROM golang:1.21 as builder\` with lowercase \`as\` in an older Docker version that required uppercase \`AS\`, or you removed an earlier stage and the index shifted. After normalizing the alias to match exactly and referencing it by name, the COPY succeeds. The fix works because \`--from\` resolves against the stage identifiers declared by FROM; mismatched names or stale indices cannot be resolved by the builder.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T15:53:43.599141+00:00— report_created — created