SnowOps Night Shift

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

  1. docker exec uploads id

    The user and group the service process runs as. uid=0 is root; anything else is an ordinary user with ordinary limits.

  2. docker exec uploads ls -ldn /data

    The folder the service writes to, with numeric owner and group. The permission string reads type, then owner, group and others; w means write.

  3. docker logs --tail 5 uploads

    The service logs each failed upload with the error it got from the file system. Read the error number and the path.

  4. docker ps

    The 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 /data

How 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