Docker Machine

From Training Material
Jump to navigation Jump to search


Author


Installation

<syntaxhighlight lang="Bash"> $ sudo -i $ curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine $ chmod +x /usr/local/bin/docker-machine $ curl -L https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine.bash > /etc/bash_completion.d/docker-machine.bash $ exit $ docker-machine --version </syntaxhighlight>

  • more info about installation: docs.docker.com/machine/install-machine/ and supported drivers: docs.docker.com/machine/drivers/


Docker-Machine Drivers

Amazon Web Services

<syntaxhighlight lang="Bash"> docker-machine create \

 --driver amazonec2 \
 --amazonec2-vpc-id vpc-6f559a0a \
 --amazonec2-access-key AKI...EQA \
 --amazonec2-secret-key A6Z...AKM \
 --amazonec2-region eu-west-1 \
 --amazonec2-zone b \
 --amazonec2-instance-type t2.small \
 --amazonec2-ami ami-00035f41c82244dab \
 --amazonec2-root-size 8 \
 --amazonec2-security-group myGroup \
 aws-machine-1

</syntaxhighlight>

Microsoft Azure

<syntaxhighlight lang="Bash"> docker-machine create \

 --driver azure \
 --azure-subscription-id 5a4...30d2 \
 --azure-location 'West Europe' \
 --azure-resource-group training \
 --azure-size Standard_B2s \
 --azure-vnet training \
 --azure-open-port 80 \
 azure-machine-1

</syntaxhighlight>

Oracle VirtualBox

<syntaxhighlight lang="Bash"> docker-machine create \

 --driver=virtualbox \
 --virtualbox-memory=1024 \
 --virtualbox-disk-size=4096 \
 boot2docker-machine-1

</syntaxhighlight>

Generic driver

Make sure you can connect, from server-s0 to server-s1 and server-s2 using public key authentication <syntaxhighlight lang="Bash"> $ ssh-keygen $ ssh-copy-id ubuntu@server-s1 $ ssh ubuntu@server-s1 $ exit $ ssh-copy-id ubuntu@server-s2 $ ssh ubuntu@server-s2 $ exit </syntaxhighlight>

Make sure you are using passwordless sudo and create a new docker hosts. <syntaxhighlight lang="Bash"> $ docker-machine create --driver generic --generic-ip-address server-s1 --generic-ssh-user ubuntu server-s1 $ docker-machine create --driver generic --generic-ip-address server-s2 --generic-ssh-user ubuntu server-s2 $ docker-machine ls </syntaxhighlight>

Run web server on server-s1

<syntaxhighlight lang="Bash"> $ eval $(docker-machine env server-s1) $ docker-machine active $ docker run -d -p 80:80 httpd:alpine $ eval $(docker-machine env -u) $ docker-machine active </syntaxhighlight>