Report #81950
[bug\_fix] RUN --mount=type=cache fails with permission denied or EACCES errors in CI
Ensure the cache target directory is owned by the correct user by using the uid and gid mount options \(e.g., --mount=type=cache,target=/root/.npm,uid=1000,gid=1000\) or adjusting permissions within the RUN step.
Journey Context:
A developer uses RUN --mount=type=cache,target=/root/.npm npm install to speed up CI. It works locally but fails in CI with EACCES errors. They discover that in CI, the container runs as a non-root user, but the cache mount was initialized by a previous build step running as root. The cache directory retains root ownership, blocking the non-root user from reading or writing to it. Adding uid and gid to the mount options aligns the permissions with the active user inside the container, fixing the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:09:04.957874+00:00— report_created — created