adlogix / docker-machine-nfs

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

How-to use NFS in a container's shared directory? #11

Closed phpguru closed 8 years ago

phpguru commented 8 years ago

Forgive me, @tonivdv, for being slow, but I'm not getting it.

I gave this a try and saw the exact same as the screencast video on the readme.md page, but now I'm left wondering, ok, how do I use this to map directories on my host to directories on containers?

silvamerica commented 8 years ago

In a container volume mount, you specify a path on your host (as long as it's in /Users). Since that maps to /Users inside the VM, it will be available to mount inside the container. Examples:

-v /Users/phpguru/project/application/folder:/app
-v $(pwd):/app
phpguru commented 8 years ago

So any mounts I have just instantly become NFS then? Wow, it's too simple then. Now how to go about fixing permission problems? I know, that's the holy grail, right? docker run -v /my/projects/project:/var/www/html ... is owned by 502:dialout and since cache and logs are in there, the app won't run because it can't create cache and logs.

Edit: After searching around, I tried this in the container.

$ useradd -u 502 web
$ usermod -G www-data web

Now, ls -la /var/www/html says owned by web:dialout and I can chmod & chown.

tonivdv commented 8 years ago

@phpguru Hmm odd you have to change the permissions ... normally it should work due to following nfs instruction in the /etc/export file

echo '\n"/Users" '$prop_machine_ip' -alldirs -mapall='$(id -u)':'$(id -g)'\n' | sudo tee -a /etc/exports && \
        awk '!a[$0]++' /etc/exports | sudo tee /etc/exports

You see the part -mapall='$(id -u)':'$(id -g)', this is normally the user and group from your host ... How did you run the docker-machine-nfs tool?

phpguru commented 8 years ago

Well, it's brilliant. I'm using the default docker-machine so I just did

docker-machine-nfs default

That succeeded.

$ id geoffh
uid=502(geoffh) gid=20(staff) ...

My Mac OS UserID is 502 (user didn't exist in Ubuntu) Group "staff (20)" maps over to 'dialout:20' on Ubuntu. This was on Ubuntu.15-10 if that helps. So I just created & forced a new user, web, to be uid 502 on Ubuntu and added that user to the www-data group. There's probably a fancier, more portable way to deal with this but for moving forward in development I'm good to go, I believe. Thanks for working out this tool!

I should mention that inside the docker machine, /Users is properly owned by geoffh:staff. Does that mean something isn't right in the way I'm creating mounts for containers?

Here's my docker run command:

    docker run -d \
    --name web \
    -p 80:80 \
    -p 9000:9000 \
    -e APP=web \
    -v /Users/geoffh/Code/projectA:/var/www/html \
    -v /Users/geoffh/Code/projectB:/var/projectB \
    -t ubuntulamp:latest
tonivdv commented 8 years ago

Hey @phpguru ,

I misread your initial question about permissions. You were talking about inside the container, while I was only talking about the virtualbox nfs share.

But yes, regarding permissions this is another story not related to the nfs one. I don't really have issues when using apache setup (through the official php-apache image), however I know I had issue with a nginx setup where I had to do something like usermod -u 1000 www-data

But whether you use nfs or any other file sync system, it's the same "problematic".

Cheers