Report #1245
[bug\_fix] Permission denied when writing to a BuildKit cache mount because the mount is owned by root
Add uid and gid \(and optionally mode\) to the mount: RUN --mount=type=cache,target=/app/.cache,uid=1000,gid=1000 ... . By default cache mounts are created as root:root 0755, so a non-root USER cannot write to them.
Journey Context:
We switched our image to USER appuser \(UID 1000\) and added RUN --mount=type=cache,target=/app/.cache pip install ... The build failed with 'Permission denied: /app/.cache'. We thought the cache mount would inherit the USER. BuildKit docs state cache mounts default to root ownership. Since the RUN executed as appuser, it could not write. Adding uid=1000,gid=1000 to the mount options made the cache directory writable by the runtime user while still preserving cached data across builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T19:55:25.165837+00:00— report_created — created