Skip to content

Commit

Permalink
Merge pull request #44 from universityofadelaide/use-nfs-mount
Browse files Browse the repository at this point in the history
Use Docker for Mac's NFS support
  • Loading branch information
acbramley authored Aug 30, 2018
2 parents e03c944 + 997c196 commit 6ce5d75
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docker-compose.osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
XDEBUG_CONFIG: "remote_host=docker.for.mac.localhost"
PHP_IDE_CONFIG: serverName=localhost
volumes:
- .:/code
- nfsmount:/code
- ./shared:/shared
- $HOME/.ssh/id_rsa:/root/.ssh/id_rsa

Expand All @@ -53,3 +53,11 @@ services:
redis:
image: redis:alpine
network_mode: service:web

volumes:
nfsmount:
driver: local
driver_opts:
type: nfs
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
device: ":${PWD}"
96 changes: 96 additions & 0 deletions dsh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,96 @@ dsh_pull() {
docker-compose -f ${DOCKER_COMPOSE_FILE} pull
}

# Command: ./dsh nfs
# Sets up NFS integration for OSX.
NFS_FILE=/etc/exports
NFS_LINE="/Users -alldirs -mapall=$(id -u):$(id -g) localhost"
dsh_setup_nfs() {
if [ ${HOST_TYPE} != "mac" ]; 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."
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 -f ${DOCKER_COMPOSE_FILE} down > /dev/null 2>&1
docker volume prune -f > /dev/null

osascript -e 'quit app "Docker"'

echo "== Resetting folder permissions..."
sudo chown -R "$(id -u)":"$(id -g)" .

echo "== Setting up nfs..."
sudo cp /dev/null "$NFS_FILE"
grep -qF -- "$NFS_LINE" "$NFS_FILE" || sudo echo "$NFS_LINE" | sudo tee -a "$NFS_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 🐳"
}

# Command: ./dsh rnfs
# Removes nfs setup.
dsh_remove_nfs() {
if [ ${HOST_TYPE} != "mac" ]; 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 "== Removing nfsd exports..."
sudo sed -i '' "/$(echo "$NFS_LINE" | sed 's/\//\\\//g')/d" ${NFS_FILE}
echo "== Restarting nfsd..."
sudo nfsd restart
echo "== Done"
}

dsh_help() {
printf "\nUsage: dsh COMMAND\n\n
Commands:\n
Expand All @@ -134,6 +224,12 @@ case ${COMMAND} in
l*)
dsh_logs
;;
nfs)
dsh_setup_nfs
;;
rnfs)
dsh_remove_nfs
;;
pul*)
dsh_pull
;;
Expand Down

0 comments on commit 6ce5d75

Please sign in to comment.