Last active
January 12, 2016 17:16
-
-
Save Sergic/2977309ebf033ce3bb31 to your computer and use it in GitHub Desktop.
Start docker machine with mount widows dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong... Press any key to continue..."' EXIT | |
VM=nb | |
DOCKER_MACHINE=./docker-machine.exe | |
#mount data | |
SHARE_NAME=projects | |
SHARE_PATH=c:\\home\\projects | |
MOUNT=/opt/$SHARE_NAME | |
SCRIPT=/mnt/sda1/var/lib/boot2docker/bootlocal.sh | |
if [ ! -z "$VBOX_MSI_INSTALL_PATH" ]; then | |
VBOXMANAGE=${VBOX_MSI_INSTALL_PATH}VBoxManage.exe | |
else | |
VBOXMANAGE=${VBOX_INSTALL_PATH}VBoxManage.exe | |
fi | |
BLUE='\033[1;34m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
if [ ! -f $DOCKER_MACHINE ] || [ ! -f "${VBOXMANAGE}" ]; then | |
echo "Either VirtualBox or Docker Machine are not installed. Please re-run the Toolbox Installer and try again." | |
exit 1 | |
fi | |
"${VBOXMANAGE}" showvminfo $VM &> /dev/null | |
VM_EXISTS_CODE=$? | |
set -e | |
if [ $VM_EXISTS_CODE -eq 1 ]; then | |
echo "Creating Machine $VM..." | |
$DOCKER_MACHINE rm -f $VM &> /dev/null || : | |
rm -rf ~/.docker/machine/machines/$VM | |
$DOCKER_MACHINE create -d virtualbox $VM | |
#"${VBOXMANAGE}" sharedfolder remove $VM --name $SHARE_NAME &> /dev/null | |
#"${VBOXMANAGE}" sharedfolder add $VM --name $SHARE_NAME --hostpath $SHARE_PATH --automount &> /dev/null | |
else | |
echo "Machine $VM already exists in VirtualBox." | |
fi | |
VM_STATUS=$($DOCKER_MACHINE status $VM) | |
if [ "$VM_STATUS" != "Running" ]; then | |
"${VBOXMANAGE}" sharedfolder remove $VM --name $SHARE_NAME &> /dev/null | |
"${VBOXMANAGE}" sharedfolder add $VM --name $SHARE_NAME --hostpath $SHARE_PATH --automount &> /dev/null | |
echo "Starting machine $VM..." | |
$DOCKER_MACHINE start $VM | |
yes | $DOCKER_MACHINE regenerate-certs $VM | |
$DOCKER_MACHINE ssh $VM 'echo "mkdir -p '$MOUNT'" | sudo tee '$SCRIPT | |
$DOCKER_MACHINE ssh $VM 'echo "sudo mount -t vboxsf -o rw,user '$SHARE_NAME' '$MOUNT'" | sudo tee -a '$SCRIPT | |
$DOCKER_MACHINE ssh $VM 'sh '$SCRIPT | |
else | |
echo "Machine $VM already runned." | |
fi | |
echo "Setting environment variables for machine $VM..." | |
eval "$($DOCKER_MACHINE env --shell=bash $VM)" | |
clear | |
cat << EOF | |
## . | |
## ## ## == | |
## ## ## ## ## === | |
/"""""""""""""""""\___/ === | |
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ | |
\______ o __/ | |
\ \ __/ | |
\____\_______/ | |
EOF | |
echo -e "${BLUE}docker${NC} is configured to use the ${GREEN}$VM${NC} machine with IP ${GREEN}$($DOCKER_MACHINE ip $VM)${NC}" | |
echo "For help getting started, check out the docs at https://docs.docker.com" | |
echo | |
cd | |
exec "$BASH" --login -i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment