-
-
Save 0xradical/9417cc21be63ee3a8f18 to your computer and use it in GitHub Desktop.
Use NFS instead of vboxsf in Docker Machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script will mount /Users in the boot2docker VM using NFS (instead of the | |
# default vboxsf). It's probably not a good idea to run it while there are | |
# Docker containers running in boot2docker. | |
# | |
# Usage: sudo ./boot2docker-use-nfs.sh | |
# | |
docker-machine ssh querobolsa << EOF | grep "already mounted" &> /dev/null | |
mount | grep nfs > /dev/null && \ | |
echo "/Users already mounted with NFS" && \ | |
exit | |
EOF | |
if [ "$?" == "0" ] | |
then | |
echo "NFS already mounted!" | |
exit | |
fi | |
# Run command as non root http://stackoverflow.com/a/10220200/96855 | |
B2D_IP=$(docker-machine ip querobolsa) | |
if [ "$B2D_IP" == "" ] | |
then | |
echo "Restarting querobolsa VM" | |
docker-machine start querobolsa | |
eval "$(docker-machine env querobolsa)" | |
B2D_IP=$(docker-machine ip querobolsa &> /dev/null) | |
#echo "You need to start boot2docker first: boot2docker up && \$(boot2docker shellinit) " | |
#exit -1 | |
fi | |
OSX_IP=$(ifconfig -m `route get 8.8.8.8 | awk '{if ($1 ~ /interface:/){print $2}}'` | awk 'sub(/inet /,""){print $1}') | |
RESTART_NFSD=0 | |
EXPORTS_LINE="/Users -maproot=root:admin ${OSX_IP}" | |
grep "$EXPORTS_LINE" /etc/exports > /dev/null | |
if [ "$?" != "0" ] | |
then | |
RESTART_NFSD=1 | |
# Backup exports file | |
$(cp -n /etc/exports /etc/exports.bak) && \ | |
echo "Backed up /etc/exports to /etc/exports.bak" | |
# Delete previously generated line if it exists | |
grep -v '^/Users ' /etc/exports | sudo tee /etc/exports | |
# We are using the OS X IP because the b2d VM is behind NAT | |
echo "$EXPORTS_LINE" | sudo tee /etc/exports | |
fi | |
NFSD_LINE="nfs.server.mount.require_resv_port = 0" | |
grep "$NFSD_LINE" /etc/nfs.conf > /dev/null | |
if [ "$?" != "0" ] | |
then | |
RESTART_NFSD=1 | |
# Backup /etc/nfs.conf file | |
$(sudo cp -n /etc/nfs.conf /etc/nfs.conf.bak) && \ | |
echo "Backed up /etc/nfs.conf to /etc/nfs.conf.bak" | |
echo "nfs.server.mount.require_resv_port = 0" | sudo tee /etc/nfs.conf | |
fi | |
if [ "$RESTART_NFSD" == "1" ] | |
then | |
echo "Restarting nfsd" | |
sudo nfsd update 2> /dev/null || (sudo nfsd start && sleep 5) | |
fi | |
docker-machine ssh querobolsa << EOF | |
echo "Creating /Users folder" | |
sudo mkdir -p /Users | |
echo "Unmounting /Users" | |
sudo umount /Users 2> /dev/null | |
echo "Starting nfs-client" | |
sudo /usr/local/etc/init.d/nfs-client start 2> /dev/null | |
echo "Mounting /Users" | |
sudo mount $OSX_IP:/Users /Users -o rw,async,noatime,rsize=32768,wsize=32768,proto=tcp,nfsvers=3 | |
echo "Mounted /Users:" | |
ls -al /Users | |
exit | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment