Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NFS for Mac users #183

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export MOODLE_DOCKER_DB=pgsql
# Ensure customized config.php for the Docker containers is in place
cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php

# [..] IMPORTANT: For Mac users see next point

# Start up containers
bin/moodle-docker-compose up -d

Expand All @@ -39,6 +41,21 @@ bin/moodle-docker-wait-for-db
# Shut down and destroy containers
bin/moodle-docker-compose down
```

### Mac users
Docker is known to be really slow for Mac users. Run the next commands to fix that using NFS.

```bash
# [..] Follow the "Quick start" step until the "IMPORTANT" note. Then continue with this commands
# This script will set up a NFS link between your $MOODLE_DOCKER_WWWROOT and the containers
# We change the permissions of the script to be able to execute it
chmod +x bin/nfs-script.sh
# Now we run the script
./bin/nfs-script.sh

# [..] Continue with the "Quick start" from after the "IMPORTANT" note
```

## Run several Moodle instances

By default, the script will load a single instance. If you want to run two
Expand Down
4 changes: 3 additions & 1 deletion bin/moodle-docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ fi
# Mac OS Compatbility
if [[ "$(uname)" == "Darwin" ]]; then
# Support https://docs.docker.com/docker-for-mac/osxfs-caching/
dockercompose="${dockercompose} -f ${basedir}/volumes-cached.yml"
#dockercompose="${dockercompose} -f ${basedir}/volumes-cached.yml"
# https://vivait.co.uk/labs/docker-for-mac-performance-using-nfs
dockercompose="${dockercompose} -f ${basedir}/volumes-nfs.yml"
fi


Expand Down
72 changes: 72 additions & 0 deletions bin/nfs-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/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."
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"
LINE="/System/Volumes/Data -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"
14 changes: 14 additions & 0 deletions volumes-nfs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Here we support https://vivait.co.uk/labs/docker-for-mac-performance-using-nfs
# for improved performance on mac
version: "2"
services:
webserver:
volumes:
- "nfsmount:/var/www/html"
volumes:
nfsmount:
driver: local
driver_opts:
type: nfs
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
device: ":/System/Volumes/Data/${MOODLE_DOCKER_WWWROOT}"