Why do I get permission denied writing to a Docker volume?
A named volume keeps whatever owner and mode the last writer gave its files. A container that runs as an ordinary user can only write where that user has permission. When a restore or a one-off job running as root recreates the folder, the service is left able to read but not write. Compare docker exec id with docker exec ls -ldn on the folder. In this incident a restore left /data owned by root and the service runs as uid 1000.
What it looks like
- The container is Up, and every write fails with Permission denied.
- Reads still work, so the app looks half broken.
- The folder is owned by 0:0 while the process runs as another uid.
- A restore or maintenance job ran against the volume shortly before.
Commands that find the cause
docker exec uploads idThe user and group the service process runs as. uid=0 is root; anything else is an ordinary user with ordinary limits.
docker exec uploads ls -ldn /dataThe folder the service writes to, with numeric owner and group. The permission string reads type, then owner, group and others; w means write.
docker logs --tail 5 uploadsThe service logs each failed upload with the error it got from the file system. Read the error number and the path.
docker psThe uploads container should be Up. It is: whatever fails, fails inside a running process.
What the evidence looked like
Recorded on a real system when this incident was captured for the game.
$ docker exec uploads id
uid=1000 gid=0(root) groups=0(root)Root cause
The restore recreated /data owned by root with mode 755 while the service runs as uid 1000; chowning it to 1000 fixed uploads.
The fix
Give the folder back to the user the service runs as:
docker run --rm -v uploads:/data alpine:3.20 chown -R 1000 /dataHow to prevent it
Run restores as the same uid as the service, or set ownership as the last step of the restore. Avoid chmod 777: give the folder to the one user that needs it.
More incident guides
- Docker container exits immediately after a config change
- Docker port mapping not working, empty reply
- Docker container cannot connect to the database host
- Docker container exit code 137, killed for memory
- CrashLoopBackOff after a config change
- Service returns 503 while every pod is Running
- OOMKilled and exit code 137
- Pods fail to start after a Secret change
- Requests fail after adding a NetworkPolicy
- Healthy pods restarted by a liveness probe
- Slow service with low CPU and no restarts
- Rollout stuck on ImagePullBackOff
- Pods stuck Pending with insufficient CPU
- Linux disk full: no space left on device
- systemd service keeps restarting after a deploy
- Address already in use: find what holds a port on Linux
- Linux name or service not known after a config change
- Too many open files in a systemd service