Docker Community Forums

Share and learn in the Docker community.

NFS Native Support


(Seanhandley) #1

** TL;DR I have a working solution below:NFS Native Support **

Hi there,

Has anyone successfully used the new NFS support in the latest D4M 8.03.0-ce-mac59 (23608)?

Is there specific documentation for how to get this working? I’ve been trying to get my container to sync with a directory on my mac. The OSX local filesystem is too slow for my Rails app.

I’ve tried a few things with docker-compose but I’m unsure what the IP address of the NFS server should be.

version: '2'
services:
  api:
    volumes:
      - app-sync:/app:nocopy

volumes:
  app-sync:
    driver_opts:
      type: "nfs"
      o: "addr=172.18.0.4,rw"
      device: ":/app"

I’ve had various errors regarding permissions, timeouts, and simply “invalid argument”.

Any advice would be greatly appreciated. Some kind of walkthrough would be amazing.

Cheers,
Sean


Coming from vagrant, how can/should I move to docker
File access in mounted volumes extremely slow, CPU bound
(Rollinroy) #2

Hi Sean,
I’m using NFS on mac and latest docker. I’m not certain if you want to do the nfs mount in docker or from mac and then bind-mount. I’m using the latter where I mount_nfs via mac terminal and then use -v option when running docker image. The only issue I found was that I couldn’t write to the nfs volume unless I chmod 777 the files (see an earlier post).

btw, where’s info on “new NFS support”? tia.

cheers, roy


(Seanhandley) #3

Thanks Roy.

I’ve set an NFS share in /etc/exports but I’m not sure which IP/domain I should be using in the o string.

I’m struggling to find much info on native NFS support, sadly.


(Seanhandley) #4

I have a working solution.

Run this:

LINE="/Users -alldirs -mapall=$(id -u):$(id -g) localhost"
FILE=/etc/exports
grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE

LINE="nfs.server.mount.require_resv_port = 0"
FILE=/etc/nfs.conf
grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE > /dev/null

sudo nfsd restart

Now run docker-compose up using this:

version: '2'
services:
  api:
    volumes:
      - "nfsmount:/app"

volumes:
  nfsmount:
    driver: local
    driver_opts:
      type: nfs
      o: addr=addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
      device: ":${PWD}"

This will mount the current directory (PWD) into /app inside the container.


(Dak94) #5

Hi seanhandley.

I’ve try your solution but not working for me.

On my exports I have this : /Users -alldirs -mapall=501:20 localhost

And same than you on my docker-compose but I have permission denied when I up.

I used last version of docker for Mac.


(Seanhandley) #6

Hi dak94

I’ve had similar feedback from other people also, yet it works fine on my machine (and my colleagues). There’s clearly something missing but it’s not clear what…

What do you see when you run this?

showmount -e

(Dak94) #7

I see this :
Exports list on localhost:
/Users localhost


(Seanhandley) #8

Ok, that looks fine.

Can you add this to /etc/nfs.conf ?

nfs.server.mount.require_resv_port = 0

Then run

sudo nfsd restart

and try docker-compose again?


(Dak94) #9

Yeah that’s work, thank’s.

Next step for me was to check if performance was better on my symfony app.

Thank’s for the help :wink:


(Seanhandley) #10

Great! Happy to help.

And thanks for the feedback - now I know the missing conf is what’s breaking this for others.

Original solution updated to include nfs.conf changes.


(Kianda) #11

Thanks! It is possible to have this working also with https://hub.docker.com/_/mysql/ ?
Trying to mount the mysql data (/var/lib/mysql) inside the nfs volume but it gives me failed to chown errors :frowning:

Any suggestion?


(Seanhandley) #12

Sorry, I’m not sure what you can do. This solution relies on mapping UID/GID to a known pair on OSX - as such this means you can’t chown files inside the container and expect the operation to succeed on the mounted directory.

There is an option called no_root_squash for NFS which you can add to /etc/exports but it seems the OSX version of NFS doesn’t support this feature.


(Dak94) #13

I’m coming back after a few day of work with symfony and docker volume nfs and …
It was good for perf on display website.
It was not good for development.

A lot of time were I work I have to wait when I refresh website because they don’t have access to the file that I modify.

It was maybe a issue with the sync but for development, it’s annoying to wait after modify file, it’s a waste of time.

Conclusion, it’s a lot better but for web development with symfony it’s not good I must continue to use my VM with Debian and sync file with PhpStorm …


(Seanhandley) #14

You can adjust the NFS options in your docker-compose yaml and see if you get better performance. The settings I landed on were trial and error with a Rails application. Check out the man pages for NFS options and see if tweaking them helps - remember you need to docker-compose down and docker volume prune -f between changes to the config.


(Manuele Menozzi) #15

Hi Sean,
your solution works for me thank you very much!
Just one question. Every time I reboot my Mac I need to execute a “sudo nfsd restart” before the “docker-compose up” to get it working properly. Does this happen to you?


(Archimedes Trajano) #16

I haven’t tested my plugin on the mac, but if you want to try it out https://hub.docker.com/r/trajano/nfs-volume-plugin/


(Seanhandley) #17

Hi Manuele,

No, this doesn’t happen to me - but the containers I tend to test with aren’t brought up automatically so I suspect nfsd is already running before they start.


(Manuele Menozzi) #18

Even my containers aren’t brought up automatically and I already verified that nfsd is running before bringing them up (with a “ps aux | grep nfsd”). Anyway after a Mac boot, even if nfsd is running, I have to run “sudo nfsd restart” to have those containers working.
Thank you for feedback anyway!


(Seanhandley) #19

How strange! Please let me know if you ever figure out why it’s happening.


(Archimedes Trajano) #20

It may be the same issue we have in Windows where there is a race condition of the share drive not connected yet before the containers start up. The docker managed plugins alleviate the issue by ensuring that they run BEFORE the containers.