Docker mount permissions: understand UID and GID
Lab prerequisites
Use only an approved disposable, offline Linux VM with a local Docker Engine, ordinary local volume driver, and reviewed preloaded busybox:1.37 (record its digest, platform, exact Engine version and required utilities first). Verify the active Docker context and endpoint; every bm-v06 resource name in the lesson must be unused before starting. Never reuse a pre-existing volume. Use a dedicated lab shell, run commands individually in order, and stop on unexpected errors (the explicitly labeled negative tests are exceptions). Only delete resources you created after confirming their identity. All outputs are expected, not observed; these are manual labs, not ByteMind runnable editors. Before contacting the Engine, verify the effective local endpoint including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides. Recheck the approved local image ID and native platform; if the recorded digest is unavailable, report it as unknown rather than inventing one. Use owner-set resource and time limits. If prerequisites cannot be confirmed, do the paper exercise instead. Check that the approved fixture has no declared image volumes and that the synthetic destinations and file names are unused. The bind-mount lesson alone uses a fresh host directory; do not extend it to other paths.
Writable does not mean everyone can write
Linux files and directories carry an owner user ID (UID), group ID (GID) and permission bits. A process has an effective identity. Even a read-write mount does not grant permissions denied by the filesystem. Numeric IDs matter more than matching display names. Rootless mode, user namespaces, SELinux and other security controls can introduce additional mappings or restrictions. This simple experiment uses native Linux with ordinary rootful Engine and no user namespace remapping; it does not test those other modes.
Create a private synthetic note
Use a new named volume, never host files. In the first container, the default root user writes a note and sets its permission to 600, meaning only the owner has read and write permission. The second container runs with UID and GID 10001, prints its identity and lists the numeric permissions, then tries to read. Expect a denied read (nonzero status), not a mount failure. The image must contain id, ls and chmod. Confirm the directory permits traversal and the note actually has UID 0 and mode 600. Record the permission error from cat, rather than treating an image or daemon failure as a denied read.
docker volume create bm-v06-ownershipdocker run --rm --pull=never --network none -v bm-v06-ownership:/data busybox:1.37 sh -c 'printf "private-note\n" > /data/note && chmod 600 /data/note'docker run --rm --pull=never --network none --user 10001:10001 -v bm-v06-ownership:/data busybox:1.37 sh -c 'id && ls -ln /data/note && cat /data/note'printf 'status=%s\n' "$?"Correct ownership for the intended reader
Only in this disposable fixture, change the note owner to the intended UID and GID using the default root user. Leave the 600 mode intact. The second read should now succeed and print private-note. In real applications use a reviewed ownership and identity policy rather than a recursive permission change, privileged container or world-writable mode. Remove the synthetic volume after the reader exits. Record numeric ownership and unchanged mode again before removing the fixture.
docker run --rm --pull=never --network none -v bm-v06-ownership:/data busybox:1.37 chown 10001:10001 /data/notedocker run --rm --pull=never --network none --user 10001:10001 -v bm-v06-ownership:/data busybox:1.37 sh -c 'ls -ln /data/note && cat /data/note'docker volume rm bm-v06-ownershipManual practice
Explain why a read-write mount can reject a read. Write down the process UID, file owner UID and permission mode before selecting a narrowly scoped fix.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker mount permissions: understand UID and GID — Knowledge check
Apply the concepts from this lesson.
In the ordinary rootful Linux lab, with directory traversal allowed, a read-write volume contains a mode 600 file owned by UID 0. Can UID 10001 read it without extra privileges?
Which observation helps identify a UID mismatch?
What is the best scoped correction for the lab note?