Report #39552
[bug\_fix] BuildKit \`--mount=type=cache\` seems to work locally but cache is completely empty on every CI run, causing full dependency downloads
Configure the CI/CD runner or Docker Buildx builder to use a persistent cache backend \(e.g., \`--cache-to=type=local,mode=max\` or \`type=gha\`\), or ensure the BuildKit daemon state is preserved between pipeline runs.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip install -r requirements.txt\` and it works perfectly on their laptop, cutting build times by 80%. They push to GitHub Actions and the CI run downloads all packages from scratch every time. They think the syntax is wrong or BuildKit isn't enabled in CI. After verifying BuildKit is active, they dig into BuildKit architecture. They realize \`--mount=type=cache\` caches data \*inside the BuildKit daemon's local state\*. On local Docker Desktop, the daemon is a persistent background service. In ephemeral CI runners, the daemon is destroyed after the job, taking the cache with it. The fix is to use external cache storage \(like GitHub Actions cache via \`type=gha\` or a registry cache via \`type=registry\`\) to export and import the BuildKit state across runs, or ensure the CI runner uses a persistent Docker daemon/machine.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:51:43.933605+00:00— report_created — created