Skip to content

Commit 6ce5d75

Browse files
authored
Merge pull request #44 from universityofadelaide/use-nfs-mount
Use Docker for Mac's NFS support
2 parents e03c944 + 997c196 commit 6ce5d75

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

docker-compose.osx.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
XDEBUG_CONFIG: "remote_host=docker.for.mac.localhost"
2828
PHP_IDE_CONFIG: serverName=localhost
2929
volumes:
30-
- .:/code
30+
- nfsmount:/code
3131
- ./shared:/shared
3232
- $HOME/.ssh/id_rsa:/root/.ssh/id_rsa
3333

@@ -53,3 +53,11 @@ services:
5353
redis:
5454
image: redis:alpine
5555
network_mode: service:web
56+
57+
volumes:
58+
nfsmount:
59+
driver: local
60+
driver_opts:
61+
type: nfs
62+
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
63+
device: ":${PWD}"

dsh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,96 @@ dsh_pull() {
108108
docker-compose -f ${DOCKER_COMPOSE_FILE} pull
109109
}
110110

111+
# Command: ./dsh nfs
112+
# Sets up NFS integration for OSX.
113+
NFS_FILE=/etc/exports
114+
NFS_LINE="/Users -alldirs -mapall=$(id -u):$(id -g) localhost"
115+
dsh_setup_nfs() {
116+
if [ ${HOST_TYPE} != "mac" ]; then
117+
echo "This script is OSX-only. Please do not run it on any other Unix."
118+
exit 1
119+
fi
120+
121+
if [[ $EUID -eq 0 ]]; then
122+
echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2
123+
exit 1
124+
fi
125+
126+
echo ""
127+
echo " +-----------------------------+"
128+
echo " | Setup native NFS for Docker |"
129+
echo " +-----------------------------+"
130+
echo ""
131+
132+
echo "WARNING: This script will shut down running containers."
133+
echo ""
134+
echo -n "Do you wish to proceed? [y]: "
135+
read decision
136+
137+
if [ "$decision" != "y" ]; then
138+
echo "Exiting. No changes made."
139+
exit 1
140+
fi
141+
142+
echo ""
143+
144+
if ! docker ps > /dev/null 2>&1 ; then
145+
echo "== Waiting for docker to start..."
146+
fi
147+
148+
open -a Docker
149+
150+
while ! docker ps > /dev/null 2>&1 ; do sleep 2; done
151+
152+
echo "== Stopping running docker containers..."
153+
docker-compose -f ${DOCKER_COMPOSE_FILE} down > /dev/null 2>&1
154+
docker volume prune -f > /dev/null
155+
156+
osascript -e 'quit app "Docker"'
157+
158+
echo "== Resetting folder permissions..."
159+
sudo chown -R "$(id -u)":"$(id -g)" .
160+
161+
echo "== Setting up nfs..."
162+
sudo cp /dev/null "$NFS_FILE"
163+
grep -qF -- "$NFS_LINE" "$NFS_FILE" || sudo echo "$NFS_LINE" | sudo tee -a "$NFS_FILE" > /dev/null
164+
165+
LINE="nfs.server.mount.require_resv_port = 0"
166+
FILE=/etc/nfs.conf
167+
grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a "$FILE" > /dev/null
168+
169+
echo "== Restarting nfsd..."
170+
sudo nfsd restart
171+
172+
echo "== Restarting docker..."
173+
open -a Docker
174+
175+
while ! docker ps > /dev/null 2>&1 ; do sleep 2; done
176+
177+
echo ""
178+
echo "SUCCESS! Now go run your containers 🐳"
179+
}
180+
181+
# Command: ./dsh rnfs
182+
# Removes nfs setup.
183+
dsh_remove_nfs() {
184+
if [ ${HOST_TYPE} != "mac" ]; then
185+
echo "This script is OSX-only. Please do not run it on any other Unix."
186+
exit 1
187+
fi
188+
189+
if [[ $EUID -eq 0 ]]; then
190+
echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2
191+
exit 1
192+
fi
193+
194+
echo "== Removing nfsd exports..."
195+
sudo sed -i '' "/$(echo "$NFS_LINE" | sed 's/\//\\\//g')/d" ${NFS_FILE}
196+
echo "== Restarting nfsd..."
197+
sudo nfsd restart
198+
echo "== Done"
199+
}
200+
111201
dsh_help() {
112202
printf "\nUsage: dsh COMMAND\n\n
113203
Commands:\n
@@ -134,6 +224,12 @@ case ${COMMAND} in
134224
l*)
135225
dsh_logs
136226
;;
227+
nfs)
228+
dsh_setup_nfs
229+
;;
230+
rnfs)
231+
dsh_remove_nfs
232+
;;
137233
pul*)
138234
dsh_pull
139235
;;

0 commit comments

Comments
 (0)