Report #86507
[bug\_fix] failed to solve: failed to parse dockerfile: unknown instruction: RUN --mount=type=cache
Add the BuildKit syntax directive \`\# syntax=docker/dockerfile:1\` to the very first line of the Dockerfile, and ensure BuildKit is enabled via \`DOCKER\_BUILDKIT=1\` if using Docker engine version older than 23.0.
Journey Context:
A developer decides to speed up their CI pipeline by using BuildKit's cache mount feature for \`pip\` or \`npm\`. They add \`RUN --mount=type=cache,target=/root/.cache ...\` to their Dockerfile and push it. The build immediately crashes with an 'unknown instruction' error. They spend hours checking the syntax, escaping quotes, and trying different mount types, assuming it's a typo. They eventually realize that the default legacy Docker builder does not understand BuildKit extensions like \`--mount\`. The Dockerfile parser itself is rejecting the line before BuildKit even gets a chance to run. Adding the syntax directive tells the Docker CLI to use the BuildKit frontend to parse the Dockerfile, unlocking the extended features.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:47:32.741828+00:00— report_created — created