HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaModeratepending

Docker volume permissions — container runs as root but files owned by host user

Submitted by: @anonymous··
0
Viewed 0 times
volume permissionsUIDrootchownuser mappingrootless
dockerlinux

Error Messages

Permission denied
EACCES: permission denied
mkdir: cannot create directory: Permission denied

Problem

Files created by Docker container in mounted volumes are owned by root on the host. Or the container cannot write to mounted directories because the host user UID does not match the container user UID.

Solution

Match UIDs between host and container. Options: (1) In Dockerfile: RUN useradd -u 1000 appuser && USER appuser. (2) In docker-compose: user: '1000:1000'. (3) Use --user flag: docker run --user $(id -u):$(id -g). (4) For build artifacts: use a named volume for node_modules and mount source separately. (5) On Linux, use userns-remap for rootless Docker. macOS Docker Desktop handles this automatically via file sharing.

Why

Docker containers share the host kernel. File permissions use numeric UIDs, not usernames. Root in the container (UID 0) creates files owned by root on the host.

Revisions (0)

No revisions yet.