Skip to content

Instantly share code, notes, and snippets.

@BlackMaria
Last active March 10, 2016 16:01
Show Gist options
  • Save BlackMaria/d94e6515393d40a8a420 to your computer and use it in GitHub Desktop.
Save BlackMaria/d94e6515393d40a8a420 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Issue:
# if you want to mount a directory in docker-kitematic that is not inside the /Users dir
# you need to add the share and mount it on the docker host OS
# Avoide non AlphaNumeric characters here
MOUNT_NAME="testDir"
DIR=/test
SEC=30
# By default this name will be "default" :)
DOCKER_VM_NAME=default
# to get a list of docker hostname "VBoxManage list vms"
VM=$(VBoxManage list vms | grep ^\"${DOCKER_VM_NAME}\" | awk '{print $2}' )
# Turn of VM to modify its config
VBoxManage controlvm $VM poweroff || echo $VM not running
# Add the mount with automount
VBoxManage sharedfolder add "${DOCKER_VM_NAME}" --name "${MOUNT_NAME}" -hostpath "$DIR" --automount
# if you want to remove it
# VBoxManage sharedfolder remove "${DOCKER_VM_NAME}" --name "${MOUNT_NAME}"
echo "Starting the docker VM this should take about $SEC seconds"
VBoxManage startvm --type headless $VM
# if you need to manually mount this dir
# sudo mount -t vboxsf -o rw,nodev,relatime test /test/
sleep $SEC
docker-machine ssh default "sudo mkdir -p $DIR ; sudo mount -t vboxsf -o rw,nodev,relatime $MOUNT_NAME $DIR "
# The ssh equivolant
# VM_IP=192.168.99.100
# ssh -i ~/.docker/machine/machines/default/id_rsa docker@${VM_IP} "sudo mkdir -p $DIR ; sudo mount -t vboxsf -o rw,uid=1000,gid=1000 $SHARE_NAME $DIR "
cat <<EOF >> ~/.ssh/config
Host docker
Hostname 192.168.99.100
User docker
IdentityFile ~/.docker/machine/machines/default/id_rsa
EOF
cat <<EOF >> ~/.bash_profile
eval "$(docker-machine env default)"
export DOCKER_IP=$(docker-machine ip default)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment