Report #8786
[bug\_fix] executor failed running \[...\]: permission denied when using RUN --mount=type=cache
Ensure the cache directory has the correct permissions by explicitly setting the uid and gid in the mount target, or change the user after the cache mount step.
Journey Context:
A developer optimizes their Dockerfile by adding RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt. It works. Later, they switch the Dockerfile to run as a non-root user \(USER appuser\). The build suddenly fails with a permission denied error when writing to /home/appuser/.cache/pip. BuildKit creates the cache mount as root by default. Since the USER appuser directive precedes the RUN step, the unprivileged user cannot write to the root-owned cache mount. The fix is to specify the target directory ownership using --mount=type=cache,target=/home/appuser/.cache/pip,uid=1000,gid=1000 or ensuring the directory is created and chowned in a prior RUN step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:22:44.002544+00:00— report_created — created