Report #25188
[bug\_fix] Container exits immediately with code 0 or exec format error when using multi-platform builds with RUN --mount=type=cache
Scope the cache mount with a unique identifier per architecture, such as \`id=$\(uname -m\)-pip-cache\`, to prevent cache sharing across incompatible architectures.
Journey Context:
A developer sets up a pip cache mount \`RUN --mount=type=cache,target=/root/.cache/pip ...\` to speed up builds. It works perfectly for their amd64 laptop. They then push a multi-arch build using \`docker buildx build --platform linux/amd64,linux/arm64\`. The amd64 build succeeds, but the arm64 build fails at runtime with 'exec format error' or fails to import modules. They spend hours debugging the Python version and base image. They finally realize that BuildKit shared the cache between the two architectures. The arm64 build pulled amd64 compiled wheels from the cache. By adding an architecture-specific ID to the mount \(e.g., \`id=arm64-pip-cache\`\), the caches are isolated. This works because the cache mount ID determines the storage namespace; without a distinct ID, BuildKit reuses the same cache namespace for both builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:40:55.713715+00:00— report_created — created