Docker Volume Permission Denied on Linux: UID, chown & PUID

22 min readBy Yun Sanghun (M. Yun)

In a Docker Desktop container, a user with UID 1000 tried to create a file in a volume owned by root and got Permission denied. One chown 1000:1000 on the directory fixed it, with no chmod 777. A subsequent run (2025-01-28) showed that setting PUID=1000 and PGID=1000 on a plain alpine:3.20 container changed nothing at all, and id still printed uid=0(root) gid=0(root).

Container Image FamilyDefault Runtime UID:GIDDoes PUID/PGID Work?Verified Bind-Mount Permission Fix
Official Node / n8n (node:20-alpine, n8nio/n8n)1000:1000 (node)No (env vars ignored)Run sudo chown -R 1000:1000 ./data on host directory
Official Postgres (postgres:16-alpine / Debian)70:70 (Alpine) / 999:999 (Debian)No (uses gosu/su-exec)Prefer named Docker volume or match user: "1000:1000" + chown
LinuxServer.io (lscr.io/linuxserver/*)911:911 (abc via s6-overlay)Yes (entrypoint remaps abc)Set PUID=1000 and PGID=1000 in Compose environment:
Unprivileged custom / rootless imageArbitrary non-root UIDNoSet Compose user: "${UID:-1000}:${GID:-1000}" and chown mount

Converting docker run -u 1000:1000 -v ./data:/data or LinuxServer -e PUID=1000 flags into production Compose files? Paste your command into our Docker Run to Compose Converter.

The cause is a numeric UID mismatch: the process inside the container runs as one UID, the mounted directory belongs to another (usually root or your host login account), and the first write fails with Permission denied (EACCES). A container that crashes at startup with EACCES: permission denied on a mounted host directory hits the exact same kernel check. You fix it by running the container as the owning UID (PUID/PGID on images whose entrypoint script reads them, or Compose's native user: directive), or by changing the mounted directory's ownership to match the container's numeric UID.

Tested Environment Baseline (2025-01-26 ~ 2025-01-28): Windows 11 Pro 23H2 + WSL 2 Linux Kernel 6.6.87.2-microsoft-standard-WSL2 | Official Docker Desktop (desktop-linux, Docker Engine 27.3.1, Docker Compose v2.29.7) | Images Verified: nginx:1.27-alpine (UID 101), alpine:3.20 (UID 0 / UID 1000), postgres:16-alpine (UID 70), postgres:16 Debian (UID 999), n8nio/n8n:1.76.1 (UID 1000), node:20-alpine (UID 1000), and lscr.io/linuxserver/nginx (s6-overlay abc user UID 911 ➔ PUID=1000).


UID 1000 against a root-owned directory, before and after chown

When deploying self-hosted applications on Linux (Ubuntu, Debian, AlmaLinux, Arch) or WSL 2, bind mounts (./data:/app/data) are a common way to keep application files on the host filesystem, although Docker's official documentation recommends named volumes for database and state persistence (for example, backing up /data/database.sqlite before running an Nginx Proxy Manager admin password & 2FA reset). Both storage options cross the exact same Linux kernel Virtual File System (VFS) permission check whenever a non-root container process attempts to create or modify a file.

We begin with the named-volume case on Docker Desktop. Named volume gfl-perm-data is mounted at /data inside container gfl-perm-test (container ID b3061926696a, running nginx:alpine). Because /data does not pre-exist inside the base image with non-root ownership, Docker initializes the directory as root:root (0:0) with mode drwxr-xr-x (0755), and an unprivileged user created with UID 1000 (app) is immediately refused:

Docker Desktop Exec tab in container gfl-perm-test (b3061926696a, nginx:alpine) showing /data owned by root:root (0:0, drwxr-xr-x) refusing touch /data/a.txt by user app (UID 1000)
Reproducing EACCES in container gfl-perm-test (b3061926696a, nginx:alpine) on Docker Desktop: because named volume gfl-perm-data (/data) is owned by root:root (0:0) with mode drwxr-xr-x (0755), unprivileged user app (uid=1000, gid=1000) falls into the world r-x permission class and fails with touch: /data/a.txt: Permission denied.
Linux VFS bind-mount permission topology comparing root-owned 0:0 host directories rejecting UID 1000 container writes with EACCES against chown 1000:1000 and Compose user or PUID/PGID alignment
Linux VFS Bind-Mount Triad Check: Host directories created as 0:0 (0755) force non-root container workers into the read-only world triad (EACCES), whereas aligning host ownership with Compose user: "1000:1000" or PUID/PGID grants clean owner writes.

Look closely at why the kernel rejected su app -c 'touch /data/a.txt' in container b3061926696a. When ls -ld /data prints drwxr-xr-x 2 root root 4096 /data, the three permission triads correspond to owner (rwx for UID 0), group (r-x for GID 0), and world/others (r-x for every other numeric ID). Because our unprivileged user app runs with uid=1000(app) gid=1000(app), neither its user ID nor its group ID matches 0. The kernel therefore evaluates the third triad (r-x), which allows app to traverse and list /data but denies creating, renaming, or deleting any file inside it. Notice also how named volume initialization behaves: when an empty named volume is mounted onto a path that already exists inside the image (such as /var/lib/postgresql/data), Docker copies the image directory's ownership onto the volume on first mount; when mounted at an arbitrary new path like /data, or when using a host bind mount created by sudo or Docker's daemon, the directory starts as 0:0 (0755) and blocks every non-root process.

Side-by-side comparison of root-owned mount path (/data -> 0:0, mode 0755) blocking UID 1000 versus owner-aligned mount path (1000:1000, mode 0755) allowing writes
Contrasting mount initialization states on Docker Engine 27.3.1: when a mounted directory is created with root:root (0:0) ownership and mode 0755, non-root processes (UID 1000) are blocked by the kernel VFS check (left), whereas aligning directory ownership to 1000:1000 enables full read/write access without loosening 0755 mode bits (right).

To confirm that directory ownership alone caused the failure, we do not touch the permission mode bits (no chmod 777 or chmod 775) and we do not modify the user account. Instead, we run a single chown 1000:1000 /data command as root inside the exact same container (b3061926696a) so that the directory inode's numeric owner (inode.i_uid and inode.i_gid) moves from 0:0 to 1000:1000. Because named volume metadata persists on disk across container restarts, changing the mount root ownership once (either via docker exec or via a one-shot helper container such as docker run --rm -v gfl-perm-data:/data alpine:3.20 chown -R 1000:1000 /data before launching your main service) permanently grants UID 1000 the owner rwx triad while keeping group and world access restricted to read-only (r-x). In the same container session, nothing else changed:

Docker Desktop Exec tab in container gfl-perm-test (b3061926696a) after chown 1000:1000 /data showing app:app ownership and successful touch /data/a.txt
After executing chown 1000:1000 /data inside container gfl-perm-test (b3061926696a), ls -ld /data confirms ownership moved from root:root to app:app (1000:1000) with mode drwxr-xr-x intact, allowing su app -c 'touch /data/a.txt' to create a.txt (-rw-r--r--) without chmod 777.

On 2025-01-27 I ran the bind-mount version on the same Docker Desktop setup. The mounted directory (/tmp/gfl-uid) lives inside the Docker Desktop VM, so it is a Linux filesystem with real ownership; I did not test a Windows folder. It was owned by root with mode drwxr-xr-x. Before testing the bind mount itself, it helps to automate a three-part diagnostic harness (id_and_bind_test.sh) that answers three practical questions in a single pass: first, what numeric UID and GID do popular official images actually run as by default; second, what happens when a container started with --user 1000:1000 tries to write to a root-owned bind mount before and after chown 1000:1000; and third, whether switching a web container to non-root UID 1000 prevents it from binding privileged TCP port 80 inside a standard Docker bridge network namespace:

Shell harness id_and_bind_test.sh and live execution summary auditing built-in container UIDs, /tmp/gfl-uid bind mount permissions, and port 80 sysctl
Automated shell harness (id_and_bind_test.sh) for auditing built-in container UIDs (--entrypoint id), reproducing EACCES on a root-owned Linux VM bind mount (/tmp/gfl-uid:/data), and verifying whether non-root UID 1000 can bind port 80 under net.ipv4.ip_unprivileged_port_start=0.

In real production stacks, this exact 0:0 (0755) ownership mismatch surfaces as service-specific startup crashes the moment a container mounts a freshly created host directory. For example, when postgres:16-alpine starts, its entrypoint begins as root but immediately steps down via su-exec postgres (uid=70(postgres) gid=70(postgres)) before invoking initdb -D /var/lib/postgresql/data; if the host bind mount belongs to 0:0 or 1000:1000 with mode 0755, initdb aborts with error: directory "/var/lib/postgresql/data" exists but is not writable. Likewise, n8nio/n8n:1.76.1 boots directly as non-root user node (uid=1000(node) gid=1000(node)) with no root privilege-drop phase at all, so mounting a root-owned host folder at /home/node/.n8n crashes Node.js on startup with Error: EACCES: permission denied, open '/home/node/.n8n/config'. Querying the image's built-in numeric identity first is the only reliable way to know which integer to pass to chown:

Split comparison of postgres:16-alpine (UID 70) and n8nio/n8n:1.76.1 (UID 1000) crashing on 0:0 mounts versus booting cleanly after chown 70:70 and 1000:1000
Empirical startup comparison on Docker Engine 27.3.1: mounting a root-owned (0:0, mode 0755) directory into postgres:16-alpine (UID 70) or n8nio/n8n:1.76.1 (UID 1000) aborts initialization with EACCES / not writable errors (left), whereas matching numeric ownership (70:70 and 1000:1000) allows both services to initialize cleanly (right).

Running our three-part empirical script against the Docker Desktop Linux VM (/tmp/gfl-uid) puts all three behaviors on screen in a single contiguous output. Section A queries the default process identity of postgres:16-alpine (uid=70(postgres) gid=70(postgres)), n8nio/n8n (uid=1000(node) gid=1000(node)), and nginx:alpine (uid=101(nginx) gid=101(nginx)) via docker run --rm --entrypoint id so we know the exact target integer before touching host permissions. Section B mounts /tmp/gfl-uid (initialized with owner 0:0 mode drwxr-xr-x) into an alpine:3.20 container running as root versus --user 1000:1000 before and after executing chown 1000:1000 /data. Finally, Section C tests whether a non-root process running as UID 1000 can bind directly to TCP port 80 inside a standard Docker bridge container without CAP_NET_BIND_SERVICE or root privileges:

Three-part empirical terminal run showing default image UIDs (postgres 70, n8n 1000, nginx 101), bind mount /tmp/gfl-uid EACCES before chown 1000:1000, and UID 1000 listening on port 80
Three-part empirical run on Docker Desktop: querying built-in image UIDs (postgres:16-alpine = 70, n8nio/n8n = 1000, nginx:alpine = 101), verifying that --user 1000:1000 fails on a root-owned bind mount (/tmp/gfl-uid) until chown 1000:1000, and confirming UID 1000 can bind port 80 inside a bridge container (net.ipv4.ip_unprivileged_port_start = 0).
  • Root inside the container could write to the root-owned directory. With --user 1000:1000 the same write failed with touch: /data/u1000.txt: Permission denied, and after chown 1000:1000 on the directory it went through.
  • Images don't agree on a UID. postgres:16-alpine runs as 70, n8nio/n8n as 1000 (node), and the nginx user in nginx:alpine is 101. Check with docker run --rm --entrypoint id <image> <user> before you change ownership.

When managing multi-container Docker Compose hosts, permission failures rarely happen in isolation, one container fails on a 0:0 volume, another fails because an Alpine database tag expects UID 70 on a 1000:1000 host folder, and a third fails after a PUID change leaves residual files on UID 911. Forwarding container stderr and filesystem audit events into a self-hosted log stream such as OpenObserve (:5080) lets you correlate every EACCES event by process_uid, inode_owner, and directory mode across your entire stack:

OpenObserve v0.14.2 Log Explorer (:5080) indexing docker_volume_uid_audit events across process_uid 1000, 70, and 0 against inode owners 0:0, 911:911, and 1000:1000
Centralized OpenObserve v0.14.2 (:5080) log stream (docker_volume_uid_audit) indexing container volume write failures by process_uid (1000, 70, 0), inode_owner (0:0, 911:911, 1000:1000), and mode (0755) to pinpoint UID collisions across multi-container stacks.

The kernel compares numbers, not user names

Linux filesystems don't store usernames (ubuntu, john, node). They store a 32-bit numeric User Identifier (UID) and Group Identifier (GID) inside each filesystem inode (inode.i_uid and inode.i_gid), and the kernel permission check only looks at those numbers.

  1. On the host, files you create with mkdir data or a git clone belong to your login account, often 1000 for the first user on a Linux install (check with id -u and id -g).
  2. In the container, many images run as an unprivileged user, and the number varies. The official node image has a user named node with UID 1000. The official postgres:16-alpine image uses UID 70 (the Debian-based postgres image uses 999), and the nginx user in nginx:alpine is UID 101.
  3. When they meet, a process with UID 1000 writing to a directory owned by root (UID 0) with mode 0755 is refused with EACCES (Permission denied), which is exactly what the runs above show.
+-----------------------------------------------------------------------+
|                       LINUX KERNEL VFS BOUNDARY                       |
|      Bind-Mounted Directory Inode: ./data  (ext4 / xfs on Host)       |
|      Inode Metadata:  i_uid = 1000,  i_gid = 1000,  i_mode = 0755     |
+-----------------------------------+-----------------------------------+
                                    |
          +-------------------------+-------------------------+
          |                                                   |
          v                                                   v
+-----------------------------------+   +-----------------------------------+
| Case A: Container UID == 1000     |   | Case B: Container UID == 70 / 911 |
| (e.g. node / n8n / user: 1000)    |   | (e.g. postgres:alpine / lsio 911) |
| current_fsuid() (1000) == i_uid   |   | current_fsuid() != i_uid (1000)   |
| Evaluates Owner Triad: rwx (0700) |   | Evaluates World Triad: r-x (0005) |
| RESULT: WRITE ALLOWED (Exit 0)    |   | RESULT: EACCES Permission denied! |
+-----------------------------------+   +-----------------------------------+
Comparison of container userspace /etc/passwd lookup lines against shared Linux kernel VFS struct inode numeric fields (i_uid, i_gid, i_mode)
Comparing /etc/passwd entries inside official container images against kernel stat -c '%u:%g %a' inode metadata: usernames such as node (1000), postgres (70 on Alpine, 999 on Debian), and nginx (101) exist only in container userspace, while the shared kernel VFS evaluates only numeric integers.

This separation between userspace name resolution and kernel inode integers explains two behaviors that frequently confuse administrators debugging bind mounts. First, when you run ls -l ./data on the Linux host, the ls utility reads the host's /etc/passwd file to translate each file's numeric UID into a text string; if a container running as uid=70(postgres) writes files into ./data, running ls -l on the host may display a completely unrelated local daemon name (or raw number 70) because UID 70 means something different on the host than inside the Alpine container. Second, creating a user inside your Dockerfile with the exact same username as your host account does not grant write access if the numeric UIDs differ. We can verify both rules directly in an empirical split test on alpine:3.20:

Split proof showing container user appuser with UID 1001 failing with Permission denied on a 1000:1000 directory while user node with UID 1000 writes cleanly
Proving that the Linux kernel VFS compares numeric UIDs rather than usernames: a container user named appuser with UID 1001 is denied write access to a directory owned by host user appuser with UID 1000 (left), whereas a container user named node with UID 1000 writes cleanly to the same 1000:1000 directory (right).

Even within the same software project, switching base image variants changes the built-in numeric UID under the hood. The clearest example is official PostgreSQL: on postgres:16-alpine, the postgres account is created with a fixed system ID of uid=70(postgres) gid=70(postgres), whereas on the Debian Bookworm-based postgres:16 image, the postgres account is created with uid=999(postgres) gid=999(postgres). If you migrate a Docker Compose stack from postgres:16 to postgres:16-alpine while keeping the same host bind mount (./pgdata:/var/lib/postgresql/data), the container username is still postgres, but the process UID changes from 999 to 70 and the database refuses to start until the directory ownership is updated. Plotting the effective numeric UIDs across eight common container configurations shows why checking numeric IDs is mandatory:

Dual-panel matplotlib chart showing built-in numeric UIDs across 8 container configurations and VFS write success rates on a mode 0755 directory
Empirical numeric UID distribution across eight Docker container configurations on Docker Engine 27.3.1 (left) and write compatibility against a standard host UID 1000:1000 (mode 0755) directory before and after ownership or PUID alignment (right).

Before changing any Compose file or running chown on a host directory, categorize your container image into one of four architectural families. You only need two commands to classify any image: run id -u && id -g on your Linux host to confirm your host account's numeric IDs (typically 1000 on a single-user Ubuntu or Debian server), and run docker run --rm --entrypoint id <image:tag> (plus an optional username such as postgres, nginx, or abc) to inspect the container's runtime UID and GID. Once you know whether the image uses an s6-overlay entrypoint (lscr.io/linuxserver/*), a built-in non-root account matching 1000:1000 (node, n8nio/n8n), a fixed daemon system UID (postgres:16-alpine at 70, postgres:16 at 999, nginx:alpine at 101), or a plain root process (alpine, python), use this four-family reference matrix to pick the exact remediation on the first try:

Container Image Family Built-In Runtime Identity Reads PUID/PGID? Verified Remediation Pattern
LinuxServer.io (lscr.io/linuxserver/*) uid=911(abc) gid=911(abc) Yes (via s6-overlay /init) Set PUID=1000 & PGID=1000 + chown -R 1000:1000 on existing 911 folders
Node.js / n8n (node:20-alpine, n8nio/n8n) uid=1000(node) gid=1000(node) No (ignored) sudo chown -R 1000:1000 ./data (or Compose user: "1000:1000")
PostgreSQL (postgres:16-alpine vs postgres:16) uid=70(postgres) (Alpine) / uid=999 (Debian) No (initdb requires /etc/passwd) sudo chown -R 70:70 ./pgdata or sudo setfacl -R -m u:70:rwX ./pgdata
Generic Base (alpine:3.20, python:3.12-slim) uid=0(root) gid=0(root) No (ignored) Declare user: "1000:1000" in Compose + sudo chown -R 1000:1000 ./data
Four-quadrant reference card mapping LinuxServer.io, Node.js/n8n, PostgreSQL (Alpine 70 vs Debian 999), and generic base images to their UID remediation patterns
Quick-reference lookup card verified via docker run --rm --entrypoint id on Docker Engine 27.3.1: matching each image family (LinuxServer.io s6-overlay, Node.js/n8n UID 1000, PostgreSQL UID 70/999, and generic Alpine/Python images) to its supported UID alignment mechanism.

Fix 1: PUID and PGID, but only if the image reads them

PUID and PGID are ordinary environment variables. Docker Engine and Docker Compose do nothing special with them; only an image whose startup script explicitly reads those variables and runs usermod -o -u "$PUID" and groupmod -o -g "$PGID" before dropping privileges changes anything. Passing PUID=1000 to an official Alpine, Postgres, Redis, or Node.js container simply exports an unused variable into the process environment while the container continues running under its compiled default UID. I checked this on 2025-01-28 on Docker Desktop (Windows 11, Docker Engine 27.3.1, Compose v2.29.7) with named volumes: the two alpine:3.20 cases ran in a Compose file (gfl-puid-env with PUID=1000 and PGID=1000 versus gfl-puid-user with user: "1000:1000"), and the LinuxServer.io image (lscr.io/linuxserver/nginx) ran with and without -e PUID=1000 -e PGID=1000:

Empirical comparison showing alpine:3.20 ignoring PUID=1000 PGID=1000 (uid=0) versus lscr.io/linuxserver/nginx remapping user abc from UID 911 to UID 1000
Empirical comparison on Docker Engine 27.3.1 (Compose v2.29.7): passing PUID=1000 and PGID=1000 to plain alpine:3.20 (gfl-puid-env) is completely ignored and leaves the process at uid=0(root), whereas lscr.io/linuxserver/nginx reads both variables during init, remaps internal user abc from UID 911 to UID 1000, and sets /config entries to 1000:1000.
  gfl-puid-user  | uid=1000 gid=1000 groups=1000
  gfl-puid-user  | touch: /data/user-key.txt: Permission denied
  gfl-puid-env   | uid=0(root) gid=0(root) groups=0(root),...
  gfl-puid-env   | -rw-r--r--    1 0        0                0 Jan 28 11:24 env-only.txt
    User UID:    1000
    User UID:    911
  [with PUID/PGID] id abc: uid=1000(abc) gid=1000(users) groups=1000(users),1000(users)
  [without PUID/PGID] id abc: uid=911(abc) gid=911(abc) groups=911(abc),1000(users)
  • alpine:3.20 with PUID=1000 and PGID=1000: id printed uid=0(root) gid=0(root), and the file it created was owned by 0 0. The variables had no effect.
  • alpine:3.20 with user: "1000:1000": id printed uid=1000 gid=1000, and writing to the new named volume failed with touch: /data/user-key.txt: Permission denied, because the volume's top directory belonged to root.
  • lscr.io/linuxserver/nginx with PUID=1000 and PGID=1000: the startup log showed User UID: 1000 and User GID: 1000, id abc printed uid=1000(abc) gid=1000(users), and the files it created in /config were owned by 1000:1000.
  • The same image without them: User UID: 911, id abc printed uid=911(abc) gid=911(abc), and its files in /config were owned by 911:911.

So use PUID/PGID only with images that document them, such as LinuxServer.io images. For official images that already run as a built-in non-root account (such as n8nio/n8n:1.76.1 running as uid=1000(node) gid=1000(node)) passing PUID does nothing; instead, once you align the mounted directory (/home/node/.n8n) to 1000:1000, the container writes its configuration and SQLite database cleanly without root privileges or chmod 777:

n8n v1.76.1 Workflow Editor (:5678) verifying non-root uid=1000(node) volume persistence and SQLite write access after chown 1000:1000
Live n8n 1.76.1 (:5678) container running as built-in non-root user node (uid=1000, gid=1000) on Docker Engine 27.3.1: once /home/node/.n8n is owned by 1000:1000, n8n persists config and database.sqlite cleanly and serves /healthz with {"status": "ok"}.

LinuxServer.io images include an s6-overlay entrypoint script (/init) that starts as root, reads PUID and PGID from the container environment, remaps the internal abc user's numeric UID and GID before the application starts, and updates ownership on standard /config directories. In a docker-compose.yml file, configuring a LinuxServer.io service looks like this:

services:
  app:
    image: lscr.io/linuxserver/heimdall:latest
    environment:
      - PUID=1000  # Run `id -u` on host
      - PGID=1000  # Run `id -g` on host
    volumes:
      - ./config:/config

A fuller example with a timezone, two mounts and a restart policy:

services:
  qbittorrent:
    image: lscr.io/linuxserver/qbittorrent:latest
    container_name: qbittorrent
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
    volumes:
      - /opt/stacks/qbittorrent/config:/config
      - /opt/stacks/qbittorrent/downloads:/downloads
    restart: unless-stopped

Your own values come from running id -u and id -g on the host:

id -u  # Outputs current UID (e.g., 1000)
id -g  # Outputs current GID (e.g., 1000)
Side-by-side Docker Compose templates comparing environment PUID=1000 PGID=1000 on LinuxServer.io qbittorrent against user: 1000:1000 on official node:20-alpine
Side-by-side Docker Compose templates validated on Compose v2.29.7: passing environment variables PUID=1000 and PGID=1000 to LinuxServer.io s6-overlay images (left) versus declaring the native Compose user: "1000:1000" directive on official Node.js and Python images (right).

Adding PUID later leaves your own folders on UID 911

If a LinuxServer.io container first ran without PUID and PGID configured, its internal abc user defaulted to numeric UID 911 and GID 911, and every file or custom subdirectory it created inside /config was written with owner 911:911. What happens if you later add PUID=1000 and PGID=1000 to your Compose file and recreate the container on that same volume? On 2025-01-28 I tested this exact migration path on lscr.io/linuxserver/nginx: in Stage 1 the container booted without PUID/PGID and user abc (UID 911) created a custom folder and file at /config/mydata/note.txt; in Stage 2 I removed the container and started a new one on the same volume with -e PUID=1000 -e PGID=1000:

Split comparison of the LinuxServer.io UID 911 migration trap where /config/mydata/note.txt stays on 911:911 after adding PUID=1000 versus recursive chown -R 1000:1000
Reproducing the LinuxServer.io UID 911 migration trap on lscr.io/linuxserver/nginx: adding PUID=1000 and PGID=1000 to an existing volume updates 24 standard /config paths (including nginx.conf) to 1000:1000 but leaves custom subdirectories (/config/mydata/note.txt) on 911:911 (left) until find /config -uid 911 and chown -R 1000:1000 are run (right).
  User UID:    1000
  User GID:    1000
  -rw-r--r-- 1  911  911    4 Jan 28 06:10 /config/mydata/note.txt
  -rw-rw-r-- 1 1000 1000 3308 Jan 28 06:10 /config/nginx/nginx.conf
  owners under /config (uid:gid count):
          2 0:0
         24 1000:1000
          2 911:911
sh: can't create /config/mydata/note.txt: Permission denied
touch: cannot touch '/config/mydata/new.txt': Permission denied
  • Before the change, 26 entries under /config belonged to 911:911 and 2 to 0:0.
  • After it, 24 entries were owned by 1000:1000, including /config/nginx/nginx.conf, which had been 911 911 in the first run. Two entries stayed 911:911, one of them the /config/mydata/note.txt I had created.
  • abc, now UID 1000, could not append to note.txt or create a new file in /config/mydata: Permission denied both times.

So after you change PUID/PGID, look for paths still owned by the old UID (find /config -uid 911), especially folders you added yourself, and change their owner as in Fix 3 below.


Fix 2: set user: on images without PUID support

For generic official images (Node.js, Python, Alpine, Go binaries) that have no s6-overlay entrypoint script, use Docker Compose's native user: directive (or --user 1000:1000 on the CLI) to tell the Docker daemon to spawn the container process directly with your host UID and GID instead of root:

services:
  api:
    image: node:20-alpine
    user: "1000:1000"
    volumes:
      - ./data:/app/data
services:
  backend-worker:
    image: python:3.12-slim
    user: "1000:1000"   # your host UID:GID from id -u / id -g
    volumes:
      - ./storage:/app/storage
    command: python app.py

PostgreSQL is a poor fit for arbitrary user: overrides unless the UID already exists in the container's /etc/passwd file, because its initdb binary looks up the current effective UID in /etc/passwd and aborts if no username mapping exists.

Make sure your application does not need root inside the container, for example to run apt-get at runtime or change file ownership. Ports below 1024 were not a problem in my test: a UID 1000 process listened on port 80 inside the container, where net.ipv4.ip_unprivileged_port_start was 0. With network_mode: host the host's setting applies instead, normally 1024.

Dual-panel matplotlib chart plotting /config inode ownership counts across PUID migration stages and non-root port < 1024 sysctl thresholds
Measured /config inode ownership distribution across the three LinuxServer.io PUID migration stages (26×911:911 ➔ 24×1000:1000 + 2×911:911 ➔ 26×1000:1000, left) and minimum bindable TCP port for non-root UID 1000 under bridge networking (sysctl = 0, port 80 allowed) versus host networking (sysctl = 1024, right).

Fix 3: change the owner with chown, or add a second UID with setfacl

If the host directory or named volume already exists, assign its ownership to the numeric UID that will write to it before starting the container:

sudo chown -R 1000:1000 ./data
chmod -R u+rwX ./data

For directories that were written by root (UID 0) earlier (for example after migrating from a root container to a non-root setup) a stricter version also strips all access for world/other users while using capital X so only directories receive the execute bit and regular data files remain non-executable:

# Set ownership recursively
sudo chown -R 1000:1000 ./data

# Owner: read/write; group: read; both also get execute on directories; others: nothing
sudo chmod -R u+rwX,g+rX,o-rwx ./data

When your host user (UID 1000) and a container running under a different fixed UID (such as postgres:16-alpine running as UID 70) both need read/write access to the same directory, POSIX Access Control List (ACL) entries let you grant the container's UID explicit access without loosening world permissions. Adding both a regular ACL (-m) and a default ACL (-d -m) ensures newly created subdirectories inherit the rule automatically:

# Give UID 70 read/write access, also for new files (default ACL)
sudo setfacl -R -m u:70:rwX ./data
sudo setfacl -R -d -m u:70:rwX ./data

Why not chmod -R 777

sudo chmod -R 777 ./data is the fix people reach for first because it silences Permission denied immediately. However, mode 0777 (drwxrwxrwx) allows every unprivileged user and background process on the host (including uid=65534(nobody) or another compromised container) to read and overwrite those files (databases, JWT signing keys, .env secrets, and TLS certificates included) and causes strict daemons such as PostgreSQL to refuse startup entirely. Matching the numeric UID/GID or applying a targeted POSIX setfacl rule gets the container writing while keeping world permissions at zero (---):

Linux VFS permission architecture comparing chmod -R 777 world-writable exposure against least-privilege chown 1000:1000 + chmod 0750 + POSIX setfacl -m u:70:rwX
Comparing host directory permission models on Linux VFS: chmod -R 777 (0777) exposes credentials and databases to every local UID and breaks PostgreSQL strict mode checks, whereas combining chown -R 1000:1000, chmod u+rwX,g+rX,o-rwx (0750), and POSIX setfacl (-m u:70:rwX, -d -m u:70:rwX) grants dual read/write access to host UID 1000 and container UID 70 with zero world permissions.

What I didn't test

To keep the scope of these empirical runs explicit, note the following boundaries between the baseline Windows 11 Docker Desktop tests and the extended container verifications:

  • Native bare-metal Linux host bind mounts vs Docker Desktop VM paths: The original four baseline captures (ID 3995, ID 3996, ID 4168, ID 4448) ran on Docker Desktop for Windows 11 using named volumes and a bind mount inside the Linux VM (/tmp/gfl-uid), rather than a Windows NTFS/ReFS path (C:\Users\...).
  • POSIX ACL support on underlying filesystems: While we verified setfacl -R -m u:70:rwX and getfacl inside an alpine:3.20 container backed by Linux kernel tmpfs/ext4, external network mounts (such as NFSv3 or SMB shares mounted without the acl mount option) may return Operation not supported when running setfacl.
  • Rootless Docker Engine & User Namespace Remapping (userns-remap): All runs used standard Docker Engine mode where container UID 0 maps to host UID 0 inside the VM. If you enable rootless Docker or userns-remap, container UIDs are shifted by a subuid offset (such as 100000) on the host filesystem.
Four-step production volume ownership and POSIX ACL verification runbook card verified on Docker Engine 27.3.1
Four-step production volume permission runbook verified on Docker Engine 27.3.1: auditing built-in container UIDs (--entrypoint id), clearing residual 911:911 inodes after PUID changes, locking directory mode to 0750 (chown -R 1000:1000 && chmod -R u+rwX,g+rX,o-rwx), and applying default POSIX ACLs (setfacl -d -m u:70:rwX) for multi-UID access.

Last reviewed: 2025-01-28. Runs on Docker Desktop (Windows 11, WSL 2 backend, Docker Engine 27.3.1, Compose v2.29.7): root-owned named volume vs UID 1000 (2025-01-26), bind mount vs UID 1000, image UIDs and the port 80 check (2025-01-27), and PUID/PGID on a plain image, user: "1000:1000", and the LinuxServer.io nginx image with and without PUID/PGID (2025-01-28).

Interactive Lab Verification Checklist 0 / 3 Verified
Check 1: Run docker run --rm --entrypoint id <image> <user> and id -u / id -g on the host to compare numeric UIDs before mounting host directories
Check 2: Set PUID=1000 and PGID=1000 on LinuxServer.io images before first boot, or run chown -R 1000:1000 on any residual 911:911 subfolders under /config
Check 3: Use chown -R 1000:1000 with chmod u+rwX,g+rX,o-rwx (or setfacl -R -m u:<uid>:rwX) instead of chmod -R 777 so mounts are never world-writable

Linux Bind-Mount UID/GID Ownership & PUID/PGID Q&A

Why does passing PUID=1000 and PGID=1000 do nothing on official Docker Hub images?

PUID and PGID environment variables are custom entrypoint scripts implemented by LinuxServer.io images, not built-in Docker Engine features. For official images like n8nio/n8n or postgres, align host folder ownership with chown -R 1000:1000 or set user: '1000:1000' in Compose.

Why is chmod -R 777 dangerous as a fix for Docker volume EACCES errors?

Mode 0777 grants world write access to database files, TLS keys, and config secrets across every unprivileged process on the host, and strict daemons like PostgreSQL refuse to start if their data directory permissions are wider than 0700 or 0750.

How do I fix volume ownership when I do not have sudo on a container-only runner?

Run a one-shot Alpine helper container mounted to the same named volume as root (-u 0) and execute chown -R 1000:1000 /data before launching your non-root service container.

100% Client-Side Utilities · Printable A4 Runbook

Run Prefilled Sizing Math & Download the 1-Page Runbook

Generate non-root UID 1000 Compose volume configs and decode Linux bind-mount EACCES and deleted-inode storage logs.

Paired Prefilled Calculators & Vector PDF Checklist

Yun Sanghun (M. Yun) · Linux, Docker & AI Infrastructure Engineer