Report #98685
[bug\_fix] COPY --from=0 copies from the wrong stage after a new FROM is added earlier in the Dockerfile
Name every stage with \`AS \` and reference it by name in \`COPY --from=\`. Avoid numeric stage references except for the simplest sequential files.
Journey Context:
A developer starts with two stages and uses \`COPY --from=0 /app/dist /usr/share/nginx/html\`. Later they add a dependency-download stage at the top of the Dockerfile to cache \`node\_modules\`. The numeric index of the build stage shifts from 0 to 1, so \`COPY --from=0\` now pulls from the dependency stage instead of the build stage, producing an image with no compiled assets. BuildKit uses zero-based stage ordering from the top of the Dockerfile, so numeric references are fragile. Naming the stage \`FROM node:20-alpine AS builder\` and using \`COPY --from=builder\` makes the reference stable regardless of reordering or targeted builds. The Dockerfile reference and multi-stage build docs explicitly recommend naming stages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:36:29.070594+00:00— report_created — created