Report #15984
[bug\_fix] RUN --mount=type=cache works locally but dependencies are re-downloaded on every build in CI
Configure the CI runner to persist the BuildKit cache using \`--cache-to\` and \`--cache-from\` with type=local or type=registry, or use a CI action that handles BuildKit cache persistence \(like \`docker/build-push-action\` with cache parameters\).
Journey Context:
A developer implements \`--mount=type=cache,target=/root/.cache/pip\` and is thrilled that local builds are instant. They push to GitHub Actions, but the build still takes 5 minutes. They think BuildKit cache is a lie or broken in CI. The rabbit hole: \`--mount=type=cache\` uses a local cache directory on the BuildKit daemon. In ephemeral CI environments, the daemon or the runner is destroyed after the run, taking the local cache with it. The fix works because \`--cache-to\` exports the cache metadata and layers to a persistent location \(like a registry or S3\), and \`--cache-from\` pulls it back on the next run, bridging the gap between ephemeral environments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:28:29.118041+00:00— report_created — created