Report #66821
[bug\_fix] COPY --link causes subsequent RUN instructions to fail with 'no such file or directory', or files from previous COPY instructions are missing in the final image.
Remove the --link flag from the COPY instruction. --link creates an independent layer that doesn't depend on previous layers, meaning it doesn't see files created or modified by earlier steps in the build.
Journey Context:
A developer sees the --link flag in BuildKit documentation, which promises better cache reuse by creating independent layers. They eagerly add COPY --link package.json /app/ and COPY --link . /app/ to their Dockerfile. Suddenly, their build fails or the runtime crashes because files are missing. They go down a rabbit hole of checking directory structures and file permissions. The root cause is that --link creates a completely separate filesystem snapshot. If a previous RUN command created the /app/ directory, COPY --link doesn't see it because it bypasses the normal layer stacking. Furthermore, multiple COPY --link instructions don't merge in the traditional way; they are linked independently. The fix is to remove --link unless strictly needed for advanced cross-stage caching, restoring the standard sequential layer merging behavior where each step sees the full state of previous steps.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:38:30.712038+00:00— report_created — created