Report #14417
[bug\_fix] COPY --from=0 fails or copies from the wrong stage after adding a new FROM instruction at the top of the Dockerfile.
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 working perfectly, using COPY --from=0 /app/build /app to copy artifacts from the first stage. Later, they decide to add a linting stage at the top of the Dockerfile: FROM python:3.9 AS lint. Suddenly, the build fails because the artifact path doesn't exist, or worse, it silently copies the wrong files from the new stage 0. The developer spends hours checking the build paths inside the original stage, not realizing the integer index has shifted. The robust fix is to replace integer indices with named stages. By changing the original stage to FROM node:18 AS builder and the copy instruction to COPY --from=builder, the build becomes resilient to Dockerfile reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:25:52.474074+00:00— report_created — created