Report #701
[bug\_fix] RUN --mount=type=cache rejected with 'unknown flag: --mount' or similar parse error
Add the parser directive '\# syntax=docker/dockerfile:1' as the very first line of the Dockerfile. The --mount option is part of the newer Dockerfile syntax that BuildKit downloads from the docker/dockerfile frontend; without the directive, the bundled older parser does not recognize it.
Journey Context:
A developer wants faster npm installs so they write 'RUN --mount=type=cache,target=/root/.npm npm ci'. The build immediately fails with a Dockerfile parse error about an unknown flag. They assume their BuildKit version is too old, but the real issue is that RUN --mount is a Dockerfile frontend feature, not just a BuildKit daemon feature. Adding '\# syntax=docker/dockerfile:1' to the top of the file tells the client to use the current Dockerfile syntax image, which understands --mount. The same BuildKit daemon then runs the mount successfully and reuses the npm cache across builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T11:55:37.472659+00:00— report_created — created