Report #55503
[bug\_fix] Files missing in later RUN steps when using \`COPY --link\` in Dockerfile
Remove \`--link\` from the \`COPY\` instruction if subsequent \`RUN\` steps depend on files from previous \`COPY\` or \`ADD\` instructions. \`--link\` creates an independent layer that doesn't require previous layers to exist, effectively resetting the filesystem context for that specific layer.
Journey Context:
A developer adds \`COPY --link . /app\` to their Dockerfile to optimize cache reuse and avoid unnecessary downloads. However, a later \`RUN ls /app/config\` fails, claiming the directory doesn't exist, despite an earlier \`COPY config/ /app/config/\` step. They spend hours checking the build context and paths. The rabbit hole uncovers that \`--link\` creates a completely independent layer chain. When \`COPY --link\` is used, it doesn't merge with the previous layer's filesystem state; it creates a new view. If the later \`RUN\` step relies on the merged state of previous non-\`--link\` layers, the files will be missing. The fix is to only use \`--link\` when you want to completely detach the layer from previous state \(e.g., pulling a binary from another stage without needing the build tools from earlier\), and avoiding it when layer merging is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:39:22.633354+00:00— report_created — created