Report #14045
[bug\_fix] Package manager cache \(apt/pip/npm\) is empty or corrupted in CI despite using --mount=type=cache
Add an explicit \`id\` to the cache mount \(e.g., \`--mount=type=cache,id=pip-cache,target=/root/.cache/pip\`\) and use \`sharing=locked\` if concurrent builds are writing to the cache.
Journey Context:
A developer adds \`--mount=type=cache,target=/root/.cache/pip\` to speed up CI pipelines. It works locally, but in CI, builds intermittently fail with package corruption errors or act as if the cache is empty. They dig into BuildKit's cache scoping and realize that without an explicit \`id\`, BuildKit generates a cache key based on the target directory, which can cause collisions or isolation depending on the builder instance. Furthermore, parallel CI jobs writing to the same cache mount cause race conditions. By adding an explicit \`id\` and \`sharing=locked\`, they ensure the cache is correctly shared across builds and protected from concurrent write corruption.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:25:28.013862+00:00— report_created — created