Home > other >  how to set the owner of docker bind mount automatically generated directories
how to set the owner of docker bind mount automatically generated directories

Time:12-18

In an empty directory I ran this command

 docker run -ti -u:1000 -v "$PWD/data:/data" ubuntu echo "hello"

This automatically creates a directory named "data" which is great. The problem is that although I specified user id 1000, the directory was created with owner root

My question is: how to make docker create the directory with owner set to 1000?

CodePudding user response:

The reason it's owned by root is that it's created by Docker before the container starts.

If you want it to be created by the container - and by the user running in the container - you could do

docker run -ti -u:1000 -v "$PWD:/host" ubuntu mkdir /host/data

Note that -u:1000 sets the group of the directory. Not the owner. To set the owner, you should use -u 1000 (no colon).

  • Related