myuseringithub
1/10/2017 - 11:49 AM

- Docker Machine

# USAGE: set variable VM to virtual machine name. if not default will be used.
if [[ -v VM ]]; then echo $VM; else VM=machine; fi

docker-machine start $VM
eval $(docker-machine env $VM)
# USAGE: define VM variable for VM name or use default & run.
if [[ -v VM ]]; then echo $VM; else VM=machine; fi

forwardPort() {
  port=$1
  echo "Forwarding port \"${port}\" in VM - \"${VM}\"."
  VBoxManage modifyvm "$VM" --natpf1 ",tcp,,${port},,${port}"
}

docker-machine create -d virtualbox $VM
docker-machine stop $VM

forwardPort 443

# Node NIM - inspector manager - allows for chrome debuding of node.
forwardPort 9229

for i in {80..90}
do 
  forwardPort $i
done

for i in {8080..8090}
do 
  forwardPort $i
done

# BrowserSync ports
forwardPort 9901
forwardPort 9902
forwardPort 9903

docker-machine start $VM
VBoxManage showvminfo "${VM}"
eval $(docker-machine env $VM)
docker-machine create -d virtualbox --virtualbox-memory=4096 --virtualbox-cpu-count=2 --virtualbox-disk-size=50000 <nameofVM>
# default values = cpu=1 memory=1024
docker-machine stop machine
VBoxManage modifyvm machine --cpus 2
VBoxManage modifyvm machine --memory 4096
docker-machine start machine

# Or limit it to --virtualbox-memory 512
docker-machine create -d virtualbox --virtualbox-memory <machine>

# Example
docker-machine create -d virtualbox --virtualbox-memory 16384 machine
docker-machine ssh machine "echo 'export VAR=$PWD' >> ~/.profile"
docker-machine ls

docker-machine rm -f <specificNodeName>
docker-machine ssh <VMName>
# send commands to the docker daemon of the following vm:
eval $(docker-machine env <VMName>)
# in case some problems appear regarding certificates
docker-machine regenerate-certs <machineName>

# Open ports of docker-machine
# http://stackoverflow.com/questions/36286305/how-do-i-forward-a-docker-machine-port-to-my-host-port-on-osx
docker-machine stop <VMname>
VBoxManage modifyvm "<vmname>" --natpf1 ",tcp,,80,,80"
docker-machine start <VMName>
eval $(docker-machine env <vmname>)

# List open ports: 
VBoxManage showvminfo "machine"


docker-machine ssh [machine-name] and tail -f /var/log/docker.log

____
NOTES: 

#In case of docker-machine mounts :
  • ./:/localVMPath - this will translate to the full host path C:/Users/Name/Projects:/localVMPath which is also available in the docker-machine VM (all of c:/)
  • Where are regular path is only open between localVM and container. not the host.
  

WINDOWS users notes: 
  • Use Git bash
  • Mount - enter only one of the machines and execute commands there, in order for mount to work on them.