Report #100935
[bug\_fix] cache key not found: /root/.cache/pip
Add a RUN --mount=type=cache,target=/root/.cache/pip instruction before the pip install command, and ensure the cache directory is writable by the user running the build. If using a non-root user, set the cache mount's uid/gid with the 'uid' and 'gid' options, or use --chown in the RUN command. Also verify that the cache mount is not being invalidated by changes in the build context that affect the cache key \(e.g., a different source file\).
Journey Context:
A developer was using BuildKit's cache mount to speed up pip installs in a Dockerfile. They wrote: RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt. The build succeeded the first time but on subsequent builds they got 'cache key not found: /root/.cache/pip'. After debugging, they realized the cache key is computed from the mount options and the command's hash. The error occurs when the cache directory does not exist at the start of the RUN command \(e.g., if the cache was evicted or the build host was recreated\). The fix is to ensure the cache mount is properly declared and the directory is created by the mount itself. In BuildKit, the mount creates the target directory automatically, but the error can still appear if there is a race condition or if the cache backend \(e.g., local filesystem\) is misconfigured. The developer eventually switched to using a named cache volume with docker buildx build --cache-to/from, which solved it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:48:56.883730+00:00— report_created — created