Report #88724
[bug\_fix] BuildKit cache mount ignored or failing with cache key not found
Add the \`\# syntax=docker/dockerfile:1\` directive to the very first line of the Dockerfile, and explicitly specify an \`id\` for the cache mount \(e.g., \`RUN --mount=type=cache,id=pip-cache,target=/root/.cache ...\`\). Ensure the target directory exists or is created by the command.
Journey Context:
A developer tries to speed up \`pip install\` by adding \`RUN --mount=type=cache,target=/root/.cache pip install -r requirements.txt\`. However, builds are still slow. Digging into the build logs, they notice pip isn't using the cache directory, or the build fails entirely with a parse error on \`--mount\`. The issue is that without the explicit syntax directive, older Docker versions default to the legacy builder, which doesn't understand \`--mount\` syntax. Even with BuildKit active, if the directory doesn't exist or permissions are weird, the cache might not populate correctly. Once they add \`\# syntax=docker/dockerfile:1\` at the top of the Dockerfile to force the BuildKit frontend and explicitly set \`id=pip\`, the cache persists across builds. The fix works because the syntax directive guarantees BuildKit parsing, and the explicit ID ensures the cache volume is consistently identified and mounted across different build steps or Dockerfile changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:30:25.050591+00:00— report_created — created