Report #11879
[bug\_fix] failed to parse Dockerfile: unknown flag: mount \(or: unknown flag: secret, or: Dockerfile parse error line X: unknown instruction\)
Add \# syntax=docker/dockerfile:1 \(or a specific version like \# syntax=docker/dockerfile:1.5\) as the very first line of the Dockerfile. This tells BuildKit to use the extended Dockerfile frontend that supports --mount, --secret, and other BuildKit-specific features.
Journey Context:
A developer follows a tutorial that uses RUN --mount=type=cache,target=/root/.cache pip install in a Dockerfile. They have Docker 20.x with BuildKit enabled \(DOCKER\_BUILDKIT=1\). The build fails with 'failed to parse Dockerfile: unknown flag: mount'. They verify BuildKit is active by checking docker buildx version. They try different mount syntaxes but get the same error. The issue is that even with BuildKit enabled, the default Dockerfile frontend parser only supports the original Dockerfile syntax — it doesn't understand --mount, --secret, heredocs, or other BuildKit extensions. The \# syntax=docker/dockerfile:1 directive tells BuildKit to use the Docker-provided extended frontend image \(docker/dockerfile:1\) which includes support for these features. The developer adds the directive as the very first line of the Dockerfile and the build succeeds. This is especially confusing because some BuildKit features work without the directive \(like parallel builds and improved caching\) while others \(like mount, secret, and heredocs\) require it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:27:23.620484+00:00— report_created — created