Report #2592
[bug\_fix] BuildKit RUN --mount=type=cache cache is not being hit; packages are re-downloaded on every build despite no code changes.
Explicitly specify a persistent cache ID and ensure the target path exactly matches the package manager's default cache directory \(e.g., RUN --mount=type=cache,id=pip-cache,target=/root/.cache/pip pip install -r requirements.txt\).
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\` to speed up CI builds. Locally it works, but in CI the cache never hits. They spend hours checking CI cache storage configurations and BuildKit versions. The rabbit hole reveals two issues: first, without an explicit \`id\`, BuildKit generates a default ID based on the target path, which can be unstable across different daemon instances or if the Dockerfile changes slightly. Second, the CI runner's BuildKit cache storage is ephemeral or not configured for persistence. By explicitly setting \`id=pip-cache\`, they guarantee a stable, named cache bucket. They also configure the CI runner to use a persistent cache backend \(like a local directory or S3\) for BuildKit, ensuring the cache survives between runs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T13:19:11.931066+00:00— report_created — created