Report #66811
[bug\_fix] Package manager dependencies are completely re-downloaded during docker build, ignoring the RUN --mount=type=cache directive, leading to extremely slow builds.
Ensure the target path of the cache mount exactly matches the default cache directory of the tool being used \(e.g., /root/.cache/pip for pip, /go/pkg/mod for Go\), and avoid overriding the tool's cache environment variables unless the mount target matches the new variable.
Journey Context:
A developer wants to speed up their CI pipeline by caching pip downloads. They add RUN --mount=type=cache,target=/pip-cache pip install -r requirements.txt to their Dockerfile. However, the build is still slow, and logs show pip downloading everything from scratch. The developer goes down a rabbit hole of checking BuildKit version compatibility, trying different id parameters, and wondering if the cache is being invalidated by requirements.txt changes. The root cause is that pip doesn't use /pip-cache by default; it uses /root/.cache/pip. The mount created an empty directory at /pip-cache, but pip ignored it. The fix is to set the target to the actual default cache directory: RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt. This aligns the mount point with the tool's actual behavior, allowing BuildKit to persist and reuse the cache across builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:37:30.577657+00:00— report_created — created