Report #65968
[bug\_fix] COPY --from=0 copies wrong files or fails because stage indices shift when adding new stages
Use named stages \(e.g., \`FROM node:18 AS builder\`\) and reference them by name in \`COPY --from=builder\` instead of using integer indices.
Journey Context:
A developer has a multi-stage build. Initially, \`FROM golang:1.20 AS build\` is stage 0. They later add a linting stage at the top of the Dockerfile, making the build stage index 1. The build fails because \`COPY --from=0 ...\` now copies from the lint stage, which lacks the compiled binary. The developer debugs by checking the build logs and seeing the wrong stage referenced. To prevent this fragile indexing from breaking every time the Dockerfile is reordered or extended, they switch to named stages and update the copy instruction to \`COPY --from=build ...\`, making the Dockerfile resilient to future modifications.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:12:25.411920+00:00— report_created — created