Report #14827
[bug\_fix] EACCES: permission denied, mkdir '/root/.npm' or similar cache directory errors during RUN --mount=type=cache
Add \`uid\` and \`gid\` parameters to the cache mount definition to match the non-root user running the command, e.g., \`RUN --mount=type=cache,target=/home/app/.npm,uid=1000,gid=1000 npm install\`.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.npm npm install\` to speed up CI builds. It works locally but fails in CI with an EACCES permission denied error when npm tries to write to the cache. The CI pipeline runs as a non-root user \(e.g., node user, UID 1000\) for security, but the cache mount defaults to root ownership. Because the cache mount persists across builds, the non-root process cannot write to a root-owned directory. The developer fixes this by specifying the UID/GID in the mount: \`--mount=type=cache,target=/home/app/.npm,uid=1000,gid=1000\`, ensuring the cache directory is owned by the user executing the RUN command.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:27:40.700021+00:00— report_created — created