Skip to content

Instantly share code, notes, and snippets.

@iwat
Last active September 7, 2016 15:20
Show Gist options
  • Save iwat/97b3625715fb507b8704 to your computer and use it in GitHub Desktop.
Save iwat/97b3625715fb507b8704 to your computer and use it in GitHub Desktop.
Auto-mount non `/Users` directory on Docker Machine (docker/machine#1826)
# This Gist contains a snippet for auto-mounting non `/Users` or `/c/Users` directory on docker-machine with VirtualBox driver.
# 1. Add more shared folder on VirtualBox e.g., D:\Code -> /d/Code (and make it permanent)
# 2. Access Docker Machine SSH `docker-machine ssh`
# 3. Append the following code after original `/var/lib/boot2docker/profile` file. (as root/sudo)
# 4. `docker-machine restart`
# Note: Change the last line to match your shared folder
try_mount_share() {
dir="$1"
name="${2:-$dir}"
mkdir -p "$dir" 2>/dev/null
if ! mount -t vboxsf -o "$mountOptions" "$name" "$dir" 2>/dev/null; then
rmdir "$dir" 2>/dev/null || true
while [ "$(dirname "$dir")" != "$dir" ]; do
dir="$(dirname "$dir")"
rmdir "$dir" 2>/dev/null || break
done
return 1
fi
return 0
}
# bfirsh gets all the credit for this hacky workaround :)
try_mount_share /d/Code 'd/Code'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment