adlogix / docker-machine-nfs

Activates NFS on docker-machine
MIT License
794 stars 104 forks source link

Host Files set to Root & Container Files set to 501:20 #36

Closed smyth64 closed 8 years ago

smyth64 commented 8 years ago

Hi,

So I tried to mount a local folder as a volume in my busybox.

docker run -it -v $(pwd)/test:/test busybox

Now I am in the busy box. The first thing I see is, that the /test folder has the owner 501:20. Why is this so?

Now when I create a file inside the busybox, it gets the owner root, but on my host machine the file has also the owner root. But the owner should be my user. Otherwise I have to do everything as root?

#inside busybox
touch 123

Now when I create a file in my local test folder. In the busybox it has the owner 501:20.

Is there any workaround to map the files to the right user for both, on the host and in the container?

Best Regards, Michael

tonivdv commented 8 years ago

Hello @smith64fx ,

I would have to know how you configured the NFS part on your box. Because if you do it with default configuration it should work.

See my tests step by step:

1) The 501:20 are the ids of your user and group on your host (mac os x):

toni at t-mac in ~/dev/projects/docker_test 
$ echo $(id -u):$(id -g)
501:20

2) Result when I create a file on my host:

toni at t-mac in ~/dev/projects/docker_test 
$ touch created_on_host

# ls result on my host
toni at t-mac in ~/dev/projects/docker_test 
$ ls -las
total 0
0 drwxr-xr-x   3 toni  staff  102 Jan 12 09:32 .
0 drwxr-xr-x  15 toni  staff  510 Jan 12 09:28 ..
0 -rw-r--r--   1 toni  staff    0 Jan 12 09:32 created_on_host

# ls result on the virtual box (where you'll see the 501:20)
toni at t-mac in ~/dev/projects/docker_test 
$ docker-machine ssh adlogix-dev ls -las /Users/toni/dev/projects/docker_test
total 8
     4 drwxr-xr-x    3 501      20             102 Jan 12 08:32 .
     4 drwxr-xr-x   15 501      20             510 Jan 12 08:28 ..
     0 -rw-r--r--    1 501      20               0 Jan 12 08:32 created_on_host

3) Let's create a file from inside the container

toni at t-mac in ~/dev/projects/docker_test 
$ docker run -it -v $(pwd):/test busybox 
/ # cd /test
/test # ls -las
total 8
     4 drwxr-xr-x    3 501      20             102 Jan 12 08:34 .
     4 drwxr-xr-x   20 root     root          4096 Jan 12 08:34 ..
     0 -rw-r--r--    1 501      20               0 Jan 12 08:32 created_on_host
/test # touch created_in_container
/test # ls -las
total 8
     4 drwxr-xr-x    4 501      20             136 Jan 12 08:34 .
     4 drwxr-xr-x   20 root     root          4096 Jan 12 08:34 ..
     0 -rw-r--r--    1 501      20               0 Jan 12 08:34 created_in_container
     0 -rw-r--r--    1 501      20               0 Jan 12 08:32 created_on_host

toni at t-mac in ~/dev/projects/docker_test 
$ ls -las
total 0
0 drwxr-xr-x   4 toni  staff  136 Jan 12 09:34 .
0 drwxr-xr-x  15 toni  staff  510 Jan 12 09:28 ..
0 -rw-r--r--   1 toni  staff    0 Jan 12 09:34 created_in_container
0 -rw-r--r--   1 toni  staff    0 Jan 12 09:32 created_on_host

You can see that it keeps the same user:group.

Hope this helps.

smyth64 commented 8 years ago

Thank you @tonivdv So how can I make it possible, that the user:group in the box, called 510:20 (the id from own Mac) is mapped to the user & group www:www inside my box?

Thank you!

tonivdv commented 8 years ago

@smith64fx how did you configure your box? By configuring it the default way? So by doing:

$ docker-machine --driver virtualbox test
$ docker-machine-nfs test

?

smyth64 commented 8 years ago

Hi @tonivdv Yes, right, I created it this way.

tonivdv commented 8 years ago

That's odd it doesn't behave in the same way. Can you share the /etc/exports file.

smyth64 commented 8 years ago

/Users 192.168.99.100 -alldirs -maproot=0

The question is more, how can I map my 510:20 user to www:www inside the container?

tonivdv commented 8 years ago

@smith64fx I see the issue. Actually you did not run the docker-machine-nfs with default configuration because if you would have, the /etc/export file would have been:

/Users 192.168.99.100 -alldirs -mapall=501:20
smyth64 commented 8 years ago

ok but when I change it, the files inside the docker still have the user/group of 501:20.

But I want them to be www:www, and on my local mac smith:staff.

How to achieve this?

Best Regards & Thanks! Michael

tonivdv commented 8 years ago

AFAIK this is not possible out of the box. You will have to create your own Dockerfile by creating that user etc. This is completely out of scope of this project :(

tonivdv commented 8 years ago

As this is not a bug related to this project I'm gonna close the issue.