yigal
yigal

Reputation: 4745

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

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?

Upvotes: 2

Views: 449

Answers (1)

Hans Kilian
Hans Kilian

Reputation: 25479

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).

Upvotes: 3

Related Questions