Report #76915
[bug\_fix] BuildKit --mount=type=cache not persisting data across CI runs
For local builds, ensure BuildKit is enabled. For CI environments \(like GitHub Actions\), use external cache storage \(e.g., \`--cache-to=type=registry\` and \`--cache-from=type=registry\`\) because the local BuildKit daemon state is destroyed between CI jobs.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\` to their Dockerfile. Locally, builds are blazing fast. In GitHub Actions, the build is slow every time, as if the cache doesn't exist. They initially think the \`--mount\` syntax is broken in CI. After reading BuildKit architecture docs, they realize that \`type=cache\` uses the local BuildKit daemon's storage. In ephemeral CI runners, the Docker daemon is spun up fresh for every job, destroying the local cache. The fix is to switch to registry-based caching: push the cache to the registry during the build using \`--cache-to=type=registry,ref=myrepo/cache,mode=max\`, and pull it at the start of the next build using \`--cache-from=myrepo/cache\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:42:04.347391+00:00— report_created — created