Report #12245
[bug\_fix] \`COPY --from=0\` fails or copies the wrong artifacts after adding a new \`FROM\` instruction at the beginning of the Dockerfile.
Replace numeric stage references \(e.g., \`--from=0\`\) with named stages \(e.g., \`FROM golang:1.20 AS builder\` and \`COPY --from=builder\`\).
Journey Context:
A Dockerfile has two stages: \`FROM golang AS build\` \(stage 0\) and \`FROM alpine\` \(stage 1\). The second stage uses \`COPY --from=0 /app /app\`. Later, a developer adds a linting stage at the top: \`FROM golang AS lint\`. The build breaks because \`COPY --from=0\` now resolves to the lint stage, which doesn't have the compiled binary. The debugging process involves confusion over why a previously working build suddenly fails to find the compiled artifact, leading to checking build logs and Go compilation flags. The fix works because named stages provide a stable, semantic reference that is immune to the insertion of new stages, decoupling the dependency graph from the physical order of the Dockerfile.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:24:26.460344+00:00— report_created — created