Report #8229
[bug\_fix] RUN --mount=type=cache works locally but the cache is completely empty on every run in GitHub Actions CI
Configure a persistent cache backend for BuildKit in CI \(like registry cache using ghcr.io\) via the --cache-to and --cache-from flags, or use docker/build-push-action with the cache configuration, because the default docker-container driver in CI is ephemeral.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache/pip to their Dockerfile. Locally, builds are blazing fast and dependencies are cached. In GitHub Actions, the build takes just as long as without the mount. They initially suspect the mount syntax is wrong or the CI runner is clearing directories between steps. They try adding volumes or persisting directories, but it fails. The rabbit hole reveals that BuildKit's cache mounts are stored inside the BuildKit daemon's internal state. In CI, the docker buildx create command creates a fresh, ephemeral docker-container builder for each job, which is destroyed at the end of the job. The local disk cache is lost. The fix is to use an external persistent cache backend \(like exporting the cache to the GitHub Container Registry\) so the cache state survives across ephemeral CI runners.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:59:52.305843+00:00— report_created — created