Open mauro-ni opened 6 years ago
@Plopix Can you share a step-by-step guide? 🙏
@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
, andPROJECTMAPPINGFOLDER
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.
Thrilled to see that d4m-nfs is not needed!
I blogged about my solution here https://medium.com/@sean.handley/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc
@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?
@seanhandley many thanks for your post, I commented it with the following two questions:
@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.
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?
@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.
@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
Not sure which of the following changes resolved my locking issue but it is now apparently resolved:
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.
Glad it works @patakijv - do please share your speed findings 👍
For me, MacOS 10.13.4 (17E199), works set up device like:
device: ":${PWD}/"
@seanhandley many thanks for your post
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.
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:
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/"
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
)
It doesn't work with Docker for Mac Version 17.12.0-ce-mac46