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.
docker
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.
Dockerfile
# 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.
Dockerfile
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.
Related guides
Docker "COPY --chmod not supported" (old syntax) in CIFix Docker "the --chmod option requires BuildKit" / "COPY --chmod not supported" in CI - the `--chmod` flag o…
Docker "the --mount option requires BuildKit" - Enable BuildKit in CIFix Docker "the --mount option requires BuildKit" in CI - RUN --mount cache/secret syntax used while the lega…
Docker "dockerfile parse error" - Fix Dockerfile Syntax in CIFix Docker "failed to solve: dockerfile parse error" in CI - unknown instructions, bad line continuations, or…