Report #68301
[bug\_fix] RUN --mount=type=cache fails with 'unexpected token' or is ignored by the builder
Add \`\# syntax=docker/dockerfile:1\` to the very first line of the Dockerfile and ensure BuildKit is enabled \(\`DOCKER\_BUILDKIT=1\`\).
Journey Context:
A developer wants to speed up their CI pipeline by using BuildKit's cache mount feature for package managers: \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\`. The build immediately fails with a syntax error. They check the Docker version and see it supports BuildKit. The rabbit hole involves trying different mount syntaxes and escaping characters. The root cause is that the legacy Docker builder \(which was default before Docker 23.0\) does not understand the \`--mount\` flag. Even if BuildKit is available, the Dockerfile needs the \`\# syntax=docker/dockerfile:1\` directive to explicitly invoke the external BuildKit frontend that supports these advanced features. Adding this directive resolves the parsing error and enables the cache mount.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:07:36.061380+00:00— report_created — created