Report #97151
[bug\_fix] RUN --mount=type=cache cache appears empty between builds or id is ignored
Give the cache mount a stable id and target, e.g. RUN --mount=type=cache,id=pnpm-cache,target=/root/.local/share/pnpm/store pnpm install. To persist across CI runners, export and import the BuildKit cache with --cache-to and --cache-from \(type=local, s3, gha, etc.\); the id alone only scopes the cache within one BuildKit instance.
Journey Context:
A team adds RUN --mount=type=cache,target=/root/.pnpm to speed up installs. Locally it works, but in GitHub Actions every build reinstalls dependencies. They discover that a cache mount lives in the BuildKit worker's local cache and is lost when the ephemeral runner terminates. They add a stable id and switch to docker/build-push-action with cache-to/cache-from using type=gha. Now the cache layer is saved and restored across workflow runs. The id is the namespace key; without it, BuildKit may not reuse the same cache slot.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:37:40.395743+00:00— report_created — created