Harsh Vakharia

Configure NFS with boot2docker and OS X

Problem

When boot2docker is used with default vboxfs to mount shared folder /Users, it causes permission issues. For example, services do not have right to write to folders shared from host (OS X) to boot2docker.

1. Solution

This problem can be solved using NFS to share from host (OS X) to boot2docker.

2. OS X configuration

echo "$HOME -alldirs -mapall=$(whoami) -network 192.168.59.0 -mask 255.255.255.0" | sudo tee -a /etc/exports

3. Restart NFS server daemon

sudo nfsd restart

If you don’t want to use IP range for boot2docker and want to set a fix IP address which will be assigned to boot2docker every time, run boot2docker config > $HOME/.boot2docker/profile and change LowerIP and UpperIP to same IP e.g 192.168.59.103 in $HOME/.boot2docker/profile

See boot2docker-cli configuration

4. Configure boot2docker

boot2docker ssh "echo \"#! /bin/bash
sudo umount /Users && \
sudo /usr/local/etc/init.d/nfs-client start && \
sudo mkdir -p $HOME && sudo mount -t nfs -o noatime,soft,nolock,vers=3,udp,proto=udp,rsize=8192,wsize=8192,namlen=255,timeo=10,retrans=3,nfsvers=3 -v 192.168.59.3:$HOME $HOME\" | sudo tee /var/lib/boot2docker/bootlocal.sh && \
sudo chmod 755 /var/lib/boot2docker/bootlocal.sh"

5. Restart boot2docker or run the script

sh /var/lib/boot2docker/bootlocal.sh

References

Got any questions or comments? Drop me a message on Twitter @harshjv or comment below.

Fork my blog on GitHub