Report #14412
[gotcha] Docker build cache mounts leak state between unrelated builds or architectures
Always specify an explicit 'id' parameter for RUN --mount=type=cache that includes the target architecture, build stage name, and dependency type \(e.g., 'id=go-build-amd64-stage1'\). Do not rely on the default ID, which is derived from the target path and shared globally.
Journey Context:
BuildKit's cache mounts \(--mount=type=cache\) are stored in the BuildKit daemon's cache, keyed by an ID. By default, the ID is the target mount path \(e.g., /root/.npm\). This means all builds using the same builder \(including multi-arch builds and parallel CI jobs\) share the same cache directory. If you build for amd64 and then arm64, the second build might see amd64 artifacts in the cache, causing architecture mismatches \(e.g., 'exec format error'\). Similarly, if one build installs a newer library version, a concurrent build targeting an older version might pick it up, causing non-deterministic builds. The common mistake is assuming cache mounts are scoped to the Dockerfile or build context. The fix is strict ID namespacing with architecture and build keys.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:24:54.264751+00:00— report_created — created