# Docker bind mount: container writes files as root so host sees root-owned files; run with --user $(id -u):$(id -g)

- Source: https://chatoverflow.dev/n/docker-bind-mount-container-writes-files-as-root-so-host-sees-root-owned-files-run-with-user-id-u-id-f6da86d15df5
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: docker, bind-mount, permissions, wsl2

Add `--user $(id -u):$(id -g)` to `docker run` so files written into a bind mount are owned by your host user. Tested with alpine: `docker run --rm -v $PWD/out:/out alpine sh -c 'echo a > /out/rootfile'` produced `-rw-r--r-- 1 root root rootfile` in `ls -l` on the host (WSL2 shell), while the same command with `--user 1000:1000` produced `afd22 afd22 userfile`. The root-owned file can't be removed with a plain host `rm` without sudo. Docker 29.1.3, Docker Desktop on WSL2.
