-
-
Save seanhandley/7dad300420e5f8f02e7243b7651c6657 to your computer and use it in GitHub Desktop.
version: '2' | |
services: | |
api: | |
volumes: | |
- "nfsmount:${CONTAINER_DIR}" | |
volumes: | |
nfsmount: | |
driver: local | |
driver_opts: | |
type: nfs | |
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3 | |
device: ":${SOURCE_DIR}" |
export CONTAINER_DIR=/myapp | |
export SOURCE_DIR=/Users/me/myapp |
#!/usr/bin/env bash | |
OS=`uname -s` | |
if [ $OS != "Darwin" ]; then | |
echo "This script is OSX-only. Please do not run it on any other Unix." | |
exit 1 | |
fi | |
if [[ $EUID -eq 0 ]]; then | |
echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2 | |
exit 1 | |
fi | |
echo "" | |
echo " +-----------------------------+" | |
echo " | Setup native NFS for Docker |" | |
echo " +-----------------------------+" | |
echo "" | |
echo "WARNING: This script will shut down running containers and prune docker volumes." | |
echo "" | |
echo -n "Do you wish to proceed? [y]: " | |
read decision | |
if [ "$decision" != "y" ]; then | |
echo "Exiting. No changes made." | |
exit 1 | |
fi | |
echo "" | |
if ! docker ps > /dev/null 2>&1 ; then | |
echo "== Waiting for docker to start..." | |
fi | |
open -a Docker | |
while ! docker ps > /dev/null 2>&1 ; do sleep 2; done | |
echo "== Stopping running docker containers..." | |
docker-compose down > /dev/null 2>&1 | |
docker volume prune -f > /dev/null | |
osascript -e 'quit app "Docker"' | |
echo "== Resetting folder permissions..." | |
U=`id -u` | |
G=`id -g` | |
sudo chown -R "$U":"$G" . | |
echo "== Setting up nfs..." | |
LINE="/Users -alldirs -mapall=$U:$G localhost" | |
FILE=/etc/exports | |
sudo cp /dev/null $FILE | |
grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE > /dev/null | |
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 | |
echo "== Restarting nfsd..." | |
sudo nfsd restart | |
echo "== Restarting docker..." | |
open -a Docker | |
while ! docker ps > /dev/null 2>&1 ; do sleep 2; done | |
echo "" | |
echo "SUCCESS! Now go run your containers 🐳" |
Seems to be broken for docker desktop > 3.2.2
Firstly thanks for this script @seanhandley, you've helped so many of us! 🙇
Seems to be broken for docker desktop > 3.2.2
Running Docker Desktop (for mac) v3.5.1 and working fine here 🙆.
I'm open to suggestions for how to handle recreating volumes in a more targeted way 👍
If we're talking about only removing volumes for the current docker project, docker down -v
may be a nicer solution 😸. Removes only named volumes from the compose file (See docker-compose down documentation)
@jamsinclair yeah now it's working with v3.5.1, but thanks to the new docker volumes management (mutagen). No need for NFS volumes anymore (you can also remove your old :cached and :delegated flags)
@dev-danim appreciate the update! Do you have any links around that? I don't see much mention of volume performance improvements in any of the docker blog and github material I'm browsing.
Edit: From what I can gather Docker went with "gRPC FUSE" instead of mutagen that has improved performance and made :delegated
, :cached
and :ro
flags redundant. Still trying to track down which version this moved from experimental to stable. Seems to have flown under the radar.
tldr; as @dev-danim pointed out just update to the latest Docker Desktop build 😸. You may not need NFS mounts anymore.
Relevant Links:
Is there any special requirement for M1 macs? I am struggling to start containers on it.
Stuck here -> data: addr=192.168.65.2,nolock,hard,nointr,nfsvers=3: invalid argument
I keep trying to follow this guide and no matter how much I try to adjust permissions, it still continues to display an error and state: "Operation Not Supported"
I've allowed full disk access for iterm, console, nfsd.
My root cause it probably because my projects dont live in my home directory. They are on a separate volume, which I have still listed in my /etc/exports folder:
/System/Volumes/Data/Users -alldirs -mapall=501:20 localhost
/Volumes/Data/Docker -alldirs -mapall=501:20 localhost
/Volumes/Media -alldirs -mapall=501:20 localhost