Report #65328
[bug\_fix] ERROR: failed to solve: failed to compute cache key: ... or cache mount corruption/lock errors during parallel builds
Add \`sharing=locked\` \(or \`sharing=shared\` for read-only\) to the \`--mount=type=cache\` instruction, e.g., \`RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked pip install -r requirements.txt\`.
Journey Context:
A developer switches to BuildKit to use cache mounts for speeding up \`pip install\` or \`apt-get\` in their CI pipeline. It works locally, but in CI where multiple builds run concurrently on the same host, the builds randomly fail with lock file errors \(e.g., 'Could not get lock /var/lib/dpkg/lock'\) or corrupted cache states. They dig into BuildKit documentation and realize that by default, cache mounts use \`sharing=shared\`, which allows concurrent writes without locking, corrupting package manager state. By changing to \`sharing=locked\`, BuildKit automatically serializes access to the cache mount, allowing only one build to write at a time while others wait, preventing corruption.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:08:09.492788+00:00— report_created — created