Docker "Dockerfile: unknown flag: link" in CI
COPY --link writes the copy as an independent layer that does not depend on earlier filesystem state, which speeds up caching. The flag was added to the Dockerfile frontend in 1.4; an older frontend or the classic builder rejects it as "unknown flag: link".
What this error means
A build fails at parse time at a COPY --link ... line with dockerfile parse error: unknown flag: link.
Dockerfile:7
--------------------
7 | >>> COPY --link ./app /app
--------------------
ERROR: failed to solve: dockerfile parse error on line 7: unknown flag: linkCommon causes
An old Dockerfile frontend
A # syntax= pin below 1.4 (or no BuildKit) does not recognize --link.
The classic builder is active
DOCKER_BUILDKIT=0 routes the build through the legacy builder, which has no --link support.
How to fix it
Pin a frontend that supports --link
- Add
# syntax=docker/dockerfile:1(resolves to a current frontend). - Build with BuildKit enabled.
# syntax=docker/dockerfile:1
FROM scratch
COPY --link ./app /appDrop --link if you must use an old builder
- Remove the
--linkflag; the copy still works, just without the layered-independence optimization.
COPY ./app /appHow to prevent it
- Pin
# syntax=docker/dockerfile:1to keep modern COPY flags available. - Standardize CI on BuildKit so the frontend is current.