Report #78138
[bug\_fix] BuildKit \`--mount=type=cache\` not persisting or cross-contaminating dependency caches across architectures/branches
Specify an explicit, unique \`id\` for the cache mount \(e.g., \`--mount=type=cache,id=pip-cache-$\{TARGETARCH\},target=/root/.cache/pip\`\). Ensure the ID differs for incompatible environments to prevent corruption, and use \`sharing=locked\` if parallel builds might collide.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt to speed up builds. It works locally, but in CI, builds randomly fail with corrupted pip metadata, or dependencies installed for linux/amd64 bleed into linux/arm64 builds causing segmentation faults. They discover that BuildKit defaults the cache id to the target path. Since the cache is shared across all builds using that Dockerfile, different architectures or Python versions write incompatible binary wheels to the same cache location. By explicitly setting the id parameter to include the target architecture and Python version \(id=pip-3.11-$\{TARGETARCH\}\), they isolate the caches. The builds stabilize, and cache hits still occur correctly for the same architecture.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:44:53.885033+00:00— report_created — created