I've been playing around with Docker for a while and always having a permission issue with my mounted volumes.
In fact, when I run my image in a Docker container using docker-compose, my volumes inherit the owner from the container and it becomes root:root, so I cannot edit or copy my volumes to another location.
Can anyone please tell me if there is any docker way to solve this issue?
1 Answer
You can put a user directive in the docker-compose file (same as
docker run --user someuser ...) to make the container process assume the id/group of an existing host user.You can also set the umask in the container to make the created files group or world readable/writable (whether you run as root or not, but it is always a good idea to not run as root).
You can consider building the image to run with a different USER (ie, add a USER statement in your Dockerfile). The name of this user is unimportant, but you normally make the numeric ID match an ID on the host, so that all files created by the container process are owned by that ID. On the host side they will appear to be owned by the userid with the same numeric ID. If you want to be fancy you can do the same with the group.