Report #44116
[bug\_fix] \`Dockerfile parse error on line X: Unknown flag: mount\` when using BuildKit specific features like \`--mount=type=cache\`.
Add \`\# syntax=docker/dockerfile:1\` as the very first line of the Dockerfile to enable the BuildKit frontend parser.
Journey Context:
A developer tries to optimize their CI build times by using BuildKit's cache mounts: \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\`. The build immediately fails with a parse error. Confused, they verify they are running Docker 24.x, which defaults to BuildKit. They try \`DOCKER\_BUILDKIT=1 docker build .\`, but the error persists. They search the error and discover that while the BuildKit backend is active, the default Dockerfile frontend syntax parser is stuck in the legacy v1 mode, which doesn't understand the \`mount\` flag. By adding the magic syntax directive \`\# syntax=docker/dockerfile:1\` at the top of the file, they instruct BuildKit to use the modern frontend parser \(fetched automatically or bundled\), which unlocks the extended Dockerfile syntax features.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:31:10.412480+00:00— report_created — created