Report #28933
[bug\_fix] RUN instruction fails to find files copied in the previous step when using COPY --link
Remove the --link flag from the COPY instruction if the subsequent RUN instruction depends on those files being present in the merged filesystem, or ensure the subsequent instructions are also independent.
Journey Context:
A developer tries to optimize their Dockerfile for BuildKit parallelism by adding the --link flag to a COPY instruction: 'COPY --link package.json /app/'. The very next step is 'RUN cat /app/package.json', which fails with 'No such file or directory'. The developer is baffled because the COPY step succeeds without error. They dive into BuildKit internals and learn that --link creates a completely independent layer chain \(a linked layer\) that doesn't require the previous layers to exist. This allows BuildKit to execute these COPYs in parallel. However, because it creates an independent layer, the filesystem is not merged until the final image is assembled. Therefore, a subsequent RUN instruction \(which operates on the sequentially merged filesystem up to that point\) cannot see the files copied with --link. Removing --link forces the COPY to operate on the sequential filesystem, making the files visible to the next RUN step, at the cost of losing parallel layer creation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:57:32.153069+00:00— report_created — created