COPY –link, and the layer that stopped being rebuilt

A COPY rebuilds if any earlier layer changed, even when what it copies is identical — --link breaks that chain.

# without --link: changing the base image invalidates this
COPY --from=vendor /app/vendor /app/vendor

# with --link: the layer is independent of what precedes it
COPY --link --from=vendor /app/vendor /app/vendor

# rebuild after a base image bump, 180 MB of vendor:
#   without   41s
#   with       3s

The mechanism is that a linked copy creates its own snapshot layer rather than one derived from the previous state, so it can be reused across a changed parent. The constraint that follows is that it cannot see the filesystem it is copying into — no overwriting an existing path, no ownership derived from what is already there — so it suits copying whole directories into empty locations and not much else.