mineshaftgap / d4m-nfs

Docker for Mac with NFS for performance improvements over osxfs
295 stars 26 forks source link

Migrate from d4m-nfs to native Docker NFS Volumes discussion #55

Open mauro-ni opened 6 years ago

mauro-ni commented 6 years ago

It doesn't work with Docker for Mac Version 17.12.0-ce-mac46

$ ~/d4m-nfs/d4m-nfs.sh
[d4m-nfs] You will need to provide your Mac password in order to setup NFS.
Password:
[d4m-nfs] Copy the Moby VM APK Cache back.
[d4m-nfs] Create the script for Moby VM.
[d4m-nfs] Start and restop nfsd, for some reason restart is not as kind.
The nfsd service is already running.
[d4m-nfs] Wait until NFS is setup.
[d4m-nfs] Wait until D4M is running.
[d4m-nfs] Setup 'screen' to work properly with the D4M tty, while at it name it 'd4m'.
[d4m-nfs] Run Moby VM d4m-nfs setup script.
[d4m-nfs] Waiting until d4m-nfs setup is done
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
......................
sponomarev commented 6 years ago

@Plopix Can you share a step-by-step guide? 🙏

Plopix commented 6 years ago

@sponomarev, I have just followed what @myers provided actually. If your OSX is correctly set to exports directories you should be good. Another example

$ cat /etc/exports
/Users/plopix/Documents/PROJECTS -mapall=plopix:staff -alldirs localhost
$ cat /etc/nfs.conf
nfs.server.mount.require_resv_port = 0

Don't forget to restart sudo nfsd restart

Then I have a docker-compose.yml for Linux users (here is an extract regarding the mounts)

    engine:
        volumes:
            - '${PROJECTCOMPOSEPATH}/${PROVISIONINGFOLDERNAME}/dev/engine/php.ini:/usr/local/etc/php/php.ini:ro'
            - '${PROJECTCOMPOSEPATH}:${PROJECTMAPPINGFOLDER}:rw'

don't pay too much attention to the PROJECTCOMPOSEPATH, PROVISIONINGFOLDERNAME, and PROJECTMAPPINGFOLDER it is part of a more complex tooling mechanism

Then OSX users would run docker-compose using an override: -f docker-compose.yml -f docker-compose-osx.yml

And in this override:

version: '2.1'
services:
    engine:
        volumes:
            - "nfsmount:${PROJECTMAPPINGFOLDER}"
volumes:
  nfsmount:
    driver: local
    driver_opts:
      type: nfs
      o: addr=host.docker.internal,lock
      device: ":${PROJECTCOMPOSEPATH}/"

That is it, @myers thanks again. We don't really need d4m-nfs as before, but thanks as well to IFSight contributors and maintainers, it was awesome to have it.

Note: I did not test extensively, as it is quite new, then I can not confirm if it is 200% working, or if we will be able to work with no issue with that approach. But I don't see we should not.

if-kenn commented 6 years ago

Thrilled to see that d4m-nfs is not needed!

seanhandley commented 6 years ago

I blogged about my solution here https://medium.com/@sean.handley/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc

patakijv commented 6 years ago

@Plopix @seanhandley I just tried the nfs setup mentioned above with latest docker for mac on a ruby on rails app that has been using docker setup for a while (and previously was using d4m-nfs successfully before this issue) - I run into this issue of inability to get file locks (from rack-attack) on first reload of a page

No locks available @ rb_file_flock - /var/www/pnd/tmp/cache/D32/0F0/rack%3A%3Aattack%3A5075617%3Areq%2Fip%3A172.18.0.1

I didn't run into this problem with d4m-nfs prior to the version of docker that broke it.

Any clues as to what needs to be in place to insure file locking works as expected?

mauro-ni commented 6 years ago

@seanhandley many thanks for your post, I commented it with the following two questions:

  1. Is it possible to use a more updated version of NFS (version 4.X)?
  2. Is there a way to use relative path for ${SOURCE_DIR}?
seanhandley commented 6 years ago

@patakijv You could try setting lock in the o string in the yaml? I set nolock but it may be that you're safer using locking with your setup.

seanhandley commented 6 years ago

I found I couldn't get it working on NFSv4 @maurosbu so I downgraded. You can try it and see what happens.

As for relative paths - I'm not sure. Try it and see?

mauro-ni commented 6 years ago

@seanhandley It doesn't work.

I modified your script in order to force the use of NFSv4 by appending the following line to /etc/nfs.conf

nfs.client.mount.options = vers=4

Then within the container I did a check and I discovered that version 3 is used:

 app@14a33bc2e07c:~/www$ nfsstat -m
{CONTAINER_DIR} from :{LOCAL_DIR}
Flags: rw,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,hard,nolock,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr={IP},mountvers=3,mountproto=tcp,local_lock=all,addr={IP}

Relative paths are not working.

patakijv commented 6 years ago

@seanhandley I was actually using lock in the options as seen above in @Plopix's post, I hadn't seen your nolock usage

I am using

/etc/exports "/Users/patakijv/Work/Workspace" -alldirs -mapall=501:20 localhost

docker-compose-dev.yml

 nfsmount:
     driver: local
     driver_opts:
       type: nfs
       o: addr=host.docker.internal,lock
       device: ":${APP_ROOT_MOUNT_PATH_ON_HOST}/"

Where $APP_ROOT_MOUNT_PATH_ON_HOST is /Users/patakijv/Work/Workspace/pnd

patakijv commented 6 years ago

Not sure which of the following changes resolved my locking issue but it is now apparently resolved:

  1. I updated to (I think today's) release Version 18.03.0-ce-mac60 (23751)
  2. I restarted Docker (after the update of course - previously I had not tried restarting Docker)
  3. I changed my nfsmount options like to o: addr=host.docker.internal,rw,lock,hard,nointr,nfsvers=3 (it was previously as my prior post)

For a new docker-compose-dev.yml volume mount entry

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

Haven't yet done any file write speedtests or comparisons between using vs not using this setup.

seanhandley commented 6 years ago

Glad it works @patakijv - do please share your speed findings 👍

birkof commented 6 years ago

For me, MacOS 10.13.4 (17E199), works set up device like: device: ":${PWD}/"

@seanhandley many thanks for your post

if-kenn commented 5 years ago

We are officially deprecating this project. We will leave it in place in case it can help some people migrate to NFS volumes from the command line or compose.

spaceemotion commented 5 years ago

Since this took a bit of time and I wanted to share this with others (I hope this is the right place), here's the solution we've ended up with based on the work of @Plopix, @patakijv and @birkof:

  1. An "overwrite" compose file with contents similar to this one:

    version: '3.2'
    
    services:
     webapp:
       volumes:
         - nfsmount:/var/www/html
    
    volumes:
     nfsmount:
        driver: local
        driver_opts:
          type: nfs
          o: addr=host.docker.internal,rw,lock,hard,nointr,nfsvers=3
          device: ":${PWD}/application/"
  2. A helper script for starting the setup on OSX that takes care of fixing various permission issues:

    #!/bin/bash
    
    NFS_CONF="/etc/nfs.conf"
    NFS_EXPORTS="/etc/exports"
    WORKING_DIR=$(pwd)
    
    prepare_nfs()
    {
       echo "Checking NFS mounts + permissions"
    
       local do_restart=0
    
       # Update NFS config
       if [[ $(grep -c "require_resv_port" "$NFS_CONF") -eq 0 ]]; then
           echo " - Updating config ($NFS_CONF)"
           echo "nfs.server.mount.require_resv_port = 0" | exec sudo tee -a "$NFS_CONF" > /dev/null
    
           do_restart=1
       fi
    
       # Fix NFS permission errors
       if [[ $(grep -c "$WORKING_DIR" "$NFS_EXPORTS") -eq 0 ]]; then
           echo " - Updating exports ($NFS_EXPORTS)"
           echo "\"$WORKING_DIR\" localhost -alldirs -mapall=501:20" | exec sudo tee -a "$NFS_EXPORTS" > /dev/null
    
           do_restart=1
       fi
    
       if [[ do_restart -eq 1 ]]; then
           echo " - Restarting NFS service"
           exec sudo nfsd restart
       fi
    }
    
    main()
    {
       prepare_nfs
       docker-compose -f docker-compose.yaml -f docker-compose-osx.yaml restart
    }
    
    main

(we have our local application contents in ./application which gets mounted to /var/www/html)