Skip to content

Instantly share code, notes, and snippets.

@ehazlett
Last active March 28, 2019 18:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ehazlett/38ba224ae8bba348da2e to your computer and use it in GitHub Desktop.
Save ehazlett/38ba224ae8bba348da2e to your computer and use it in GitHub Desktop.
Using NFS with boot2docker

NFS Server

OS X Host

Note: you will need sudo access. Add the following to /etc/exports

/Users -alldirs -maproot=root:wheel -network 192.168.99.0 -mask 255.255.255.0

Restart NFS:

sudo nfsd restart

Linux Host

Note: you will need sudo access and NFS server (sudo apt-get install -y nfs-kernel-server on debian). Add the following to /etc/exports

/home 192.168.99.0/24(rw,no_root_squash,no_subtree_check)

Restart NFS

sudo systemctl restart nfs-kernel-server

Boot2Docker

You will need to remove the existing shared folder at /Users (only if on OS X). You can do this with (make sure the VM is stopeed):

VBoxManage sharedfolder remove [vm-name] --name Users

Start the VM and ssh into it. Add the following to /var/lib/boot2docker/profile:

OS X Host

mkdir /Users
sudo mount -t nfs -o vers=3,nolock,udp 192.168.99.1:/Users /Users

Linux Host

mkdir -p /mnt/home
mount -t nfs -o vers=3,nolock,udp 192.168.99.1:/home /mnt/home
for USERDIR in /mnt/home/*
do
    USER=`basename $USERDIR`
    ln -sf /mnt/home/$USER /home/$USER
done

Reboot the VM. You should now have NFS in b2d and be able to do things like:

docker run -v $(pwd):/dest/in/container ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment