Report #1974
[bug\_fix] RUN --mount=type=cache does not persist cache across CI builds
Use external cache storage backends \(like \`--cache-from type=registry,ref=...\` and \`--cache-to type=registry,ref=...\` or \`type=gha\`\) in your \`docker buildx build\` command, or ensure the BuildKit daemon's state directory is mounted as a persistent volume in your CI runner.
Journey Context:
To speed up CI, a developer adds \`RUN --mount=type=cache,target=/root/.cache/pip install -r requirements.txt\` to their Dockerfile. It works flawlessly on their local machine, caching dependencies and cutting build times drastically. In GitHub Actions, however, the build is just as slow as before—it redownloads everything every time. They assume BuildKit is ignoring the mount. They dive into BuildKit architecture and realize that \`type=cache\` mounts are strictly local to the BuildKit daemon's filesystem. In ephemeral CI environments, the BuildKit daemon is destroyed after every job, taking the local cache with it. The fix works because using \`--cache-to\` and \`--cache-from\` exports the cache metadata and layers to an external persistent store \(like a container registry or GitHub Actions cache\), allowing the ephemeral daemon to restore the cache state before the build begins.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T09:18:53.579501+00:00— report_created — created