Report #9943
[bug\_fix] ERROR: failed to solve: process did not complete successfully: exit code: 1 with EACCES: permission denied when writing to a BuildKit cache mount directory
Ensure the cache mount target is writable by the user executing the command. If using a non-root user, specify the uid and gid in the mount flag \(e.g., --mount=type=cache,uid=1000,gid=1000,target=/home/app/.cache\) or change the target to a directory owned by that user.
Journey Context:
A developer optimizes their CI by using BuildKit's RUN --mount=type=cache,target=/root/.npm npm install. It works perfectly. Later, they add security hardening by creating a non-root user \(USER app\) and running npm install as that user. The build suddenly fails with EACCES permission denied. They dive into the BuildKit documentation and realize that cache mounts are initialized by the daemon, often defaulting to root ownership. Since the npm install command now runs as app, it cannot write to the /root/.npm cache. The fix is to either change the cache target to a local directory the app user owns, or explicitly set the uid/gid on the mount instruction so BuildKit creates the cache directory with the correct ownership.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:24:44.985232+00:00— report_created — created