Skip to content

Instantly share code, notes, and snippets.

@ghugues
Created September 20, 2016 21:14
Show Gist options
  • Select an option

  • Save ghugues/8988d0fbc63ed0929b05d951c832e02e to your computer and use it in GitHub Desktop.

Select an option

Save ghugues/8988d0fbc63ed0929b05d951c832e02e to your computer and use it in GitHub Desktop.
Mount a non /Users directory as a data volume on OS X
#!/bin/sh
#
# This script will automatically mount the shared folder named `sharedFolderName`
# on `targetDirectory` when the docker machine starts.
#
# This script must be located at /var/lib/boot2docker/bootlocal.sh on the docker machine.
#
# The shared folder must be configured in VirtualBox shared folders first. The name should be the
# same as `sharedFolderName` (see below) and the path should be the path (on your host machine) to
# the directory that you want to mount.
#
# The folder on the host machine must be readable and writable by VirtualBox. Also, it appears that
# VirtualBox doesn't have (or doesn't use) root privileges on the host when doing the mount. As a
# result, if the host directory is owned by root (and not writable by anyone else), you will likely
# run into errors.
# If you're getting a 'Protocol error' when trying to write to this folder from the docker machine,
# it's typical of a permissions error on the host. Start by making yourself the owner of the host
# directory. If it doesn't work, make it `rwx` for everyone (not ideal but that should work).
#
# See https://github.com/docker/machine/issues/1826#issuecomment-143863060
# https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md (local customisation)
# https://github.com/boot2docker/boot2docker/blob/master/rootfs/rootfs/etc/rc.d/vbox
#
sharedFolderName="docker-volumes"
targetDirectory="/var/data/docker-volumes/"
mountOptions="rw,defaults,iocharset=utf8,uid=$(id -u docker),gid=$(id -g docker)"
# Creates the mount directory with the proper access rights
cd /
rm /tmp/bootlocal.log
mkdir -p "$targetDirectory" 2>&1 >> /tmp/bootlocal.log
chown $(id -un docker):$(id -gn docker) "$targetDirectory" 2>&1 >> /tmp/bootlocal.log
# Mount the volume
mount -t vboxsf -o "$mountOptions" "$sharedFolderName" "$targetDirectory" 2>&1 >> /tmp/bootlocal.log
# Log the result
echo "mount result : $?" >> /tmp/bootlocal.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment