Report #45013
[bug\_fix] ERROR: failed to solve: process "/bin/sh -c ..." did not complete successfully: Permission denied inside --mount=type=cache directory
Specify the user ownership in the cache mount instruction using the \`uid\` and \`gid\` parameters, e.g., \`--mount=type=cache,uid=1000,gid=1000,target=/home/app/.cache\`.
Journey Context:
A developer optimizes a Dockerfile by adding a BuildKit cache mount for pip or npm. It works perfectly when running as root. Later, adhering to security best practices, they add a non-root user \(\`USER app\`\) to the Dockerfile. Suddenly, the build fails with a permission denied error when the package manager tries to write to the cache directory. They try adding \`chown\` commands in previous \`RUN\` steps, but it fails because BuildKit cache mounts bypass the container's filesystem layers and are mounted directly at build time. By default, the cache mount inherits root ownership. The fix requires explicitly declaring the \`uid\` and \`gid\` in the mount instruction so BuildKit mounts the cache directory with the correct ownership for the non-root user.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:01:23.101309+00:00— report_created — created