Report #6011
[bug\_fix] RUN step fails with 'file not found' after using COPY --link
Remove the \`--link\` flag from the COPY instruction if subsequent RUN steps depend on the copied files, or understand that \`--link\` creates an independent layer chain where previous state is not accessible.
Journey Context:
A developer tries to optimize their Dockerfile by adding \`COPY --link package.json /app/\` before \`RUN npm install\`. The build fails immediately on the RUN step, claiming \`package.json\` does not exist. They are confused because the COPY step just succeeded. Digging into BuildKit documentation, they realize \`--link\` creates a completely independent, linked layer. It does not overlay the file onto the previous filesystem state; it creates a new mount point. Because the previous \`WORKDIR\` and OS base layer are not linked, the \`RUN\` command operates in a blank slate missing the copied file. The fix is to remove \`--link\` when the copied file is needed by subsequent \`RUN\` instructions in the same stage, reserving \`--link\` only for final binary copies where previous state is irrelevant.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:51:40.815448+00:00— report_created — created