Report #6948
[bug\_fix] COPY --from=builder fails with 'failed to compute cache key' or 'no such image' in multi-stage builds
Ensure the stage name in COPY --from= exactly matches the FROM ... AS alias, avoid naming stages the same as official images \(like node or python\), and do not rely on integer indices if you reorder stages.
Journey Context:
A developer creates a multi-stage build. Stage 1 is FROM node:16 AS build, Stage 2 is FROM nginx. They try COPY --from=build /app/dist /usr/share/nginx/html but it fails. They check the paths—/app/dist exists in the build stage. They dig into BuildKit logs and realize they originally used COPY --from=0 but reordered their FROM statements, so stage 0 is now the nginx stage. Or, they used COPY --from=node intending to copy from the official node image, but they also have a stage named node, causing a collision where BuildKit tries to copy from the local stage instead of Docker Hub. The fix works because using explicit, unique AS aliases and referencing those instead of integer indices or image names guarantees BuildKit resolves the copy source to the correct build stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:23:08.508012+00:00— report_created — created