Report #41429
[bug\_fix] COPY failed: no source files were specified or failed to compute cache key in multi-stage build
Ensure the file was actually created in the specified path in the source stage, and use named stages \(e.g., \`FROM node:18 AS builder\`\) instead of integer indices to prevent off-by-one errors when referencing stages in \`COPY --from=builder\`.
Journey Context:
A developer sets up a multi-stage build to reduce final image size. In the builder stage, they compile a binary to \`/build/myapp\`. In the final stage, they run \`COPY --from=0 /usr/local/bin/myapp /app/\`. The build fails because the file is not found. The debugging rabbit-hole involves adding \`RUN ls\` commands to the builder stage to find where the file actually ended up, and realizing they referenced the wrong path. Furthermore, using \`--from=0\` is fragile; if they add a new stage at the beginning, the indices shift. The fix is twofold: 1\) Use named stages \(\`FROM golang:1.20 AS builder\` and \`COPY --from=builder /build/myapp /app/\`\) to avoid index shifting, and 2\) Ensure the \`COPY --from\` source path exactly matches the path where the previous stage wrote the artifact.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:00:43.137509+00:00— report_created — created