Getting Started with Docker Machine - R&D Solutions

Getting Started with Docker Machine

This is the first post from a blog series dedicated to how we at R&D Solutions use the Docker tools for our core product – HawkЕngine. HawkЕngine is a software built with the goal to provide end to end Continuous Delivery process automation.

Containers are fundamentally changing the way we develop, distribute, and run software, no doubt about that. Developers can build software locally, knowing that it will run identically regardless of host environment – be it a rack in the IT department, a user’s laptop, or a cluster in the cloud. Operations engineers can concentrate on networking, resources, and uptime and spend less time configuring environments and battling system dependencies. Before we dive into our first use case and reveal how we deployed a docker private registry and setup our Continuous Delivery pipeline with Amazon Web Services (AWS), let’s talk about docker itself and show how to install a docker machine and how to provision a docker host in AWS.

 

Docker Platform

As per the official docker documentation the docker platform consists of:

  • Docker Engine – provides the core functions you need to create Docker images and run Docker containers.
  • Docker Swarm –  used to host clustering and container scheduling.
  • Docker Registry – supplies a private dedicated image registry.
  • Docker Machine – automates container provisioning on your network or in the cloud.
  • Docker Compose – defines multi-container applications.

 

Docker Engine is considered the core of the Docker platform. One interesting thing to note here is that Docker Engine contains client (cli) & server (daemon) bits itself, meaning that once installed it allows you to build images and run containers directly on your box.  I’ll not go in details how to install Docker Engine, I’d rather suggest refer to the the Docker Engine Installation docs.

We use AWS for our primary cloud provider.  We found that Docker Machine is an awesome piece of software that allows you to provision Docker hosts with Docker Engine installed (refer to the borrowed from the docker website graphic).

 

Installing Docker Machine:

For Linux users:

$ curl -L https://github.com/docker/machine/releases/download/v0.6.0/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine && \

chmod +x /usr/local/bin/docker-machine
Once installed, typing  “docker-machine” in the terminal yields the following output:
~$ docker-machine 

Usage: docker-machine [OPTIONS] COMMAND [arg...]

Create and manage machines running Docker.

Version: 0.6.0, build e27fb87

Author:

Docker Machine Contributors - <https://github.com/docker/machine>

Options:

--debug, -D Enable debug mode

-s, --storage-path "/home/rado/.docker/machine" Configures storage path [$MACHINE_STORAGE_PATH]

--tls-ca-cert CA to verify remotes against [$MACHINE_TLS_CA_CERT]

--tls-ca-key Private key to generate certificates [$MACHINE_TLS_CA_KEY]

--tls-client-cert Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT]

--tls-client-key Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY]

--github-api-token Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN]

--native-ssh Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH]

--bugsnag-api-token BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN]

--help, -h show help

--version, -v print the version

Commands:

active Print which machine is active

config Print the connection config for machine

create Create a machine

env Display the commands to set up the environment for the Docker client

inspect Inspect information about a machine

ip Get the IP address of a machine

kill Kill a machine

ls List machines

provision Re-provision existing machines

regenerate-certs Regenerate TLS Certificates for a machine

restart Restart a machine

rm Remove a machine

ssh Log into or run a command on a machine with SSH.

scp Copy files between machines

start Start a machine

status Get the status of a machine

stop Stop a machine

upgrade Upgrade a machine to the latest version of Docker

url Get the URL of a machine

version Show the Docker Machine version or a machine docker version

help Shows a list of commands or help for one command

As seen on the terminal output, docker machine provides plenty of options. I love the ease of use of this tool. No need to manually setup things at all!

 

Setting up Docker Host in AWS

Docker Machine provides AWS driver that can be configured to enable seamless docker host provisioning with AWS EC2. To provision machines on AWS the following two parameters has to be supplied – AWS Access Key ID and AWS Secret Access Key. Below is how you can use AWS credentials file to get a docker host setup.

Create the following file:

~/.aws/credentials

Add your AWS credentials to the file:

[default]

aws_access_key_id = AKID1234567890

aws_secret_access_key = MY-SECRET-KEY
As a next step run the following command to get the host running.
$ docker-machine create --driver amazonec2 aws01
The above command instructs docker machine to create an EC2 instance in AWS with name aws01, note that the AWS driver allows you to choose AWS region, vpc, vm type image etc..  For the full list of options refer to the docs here.

 

Connecting to the AWS Docker Host

You need to setup your shell to point to the docker daemon:

$ eval "$(docker-machine env aws01)"

Check if the shell is configured:

$ env | grep DOCKER


DOCKER_HOST=tcp://53.13.134.62:2376

DOCKER_MACHINE_NAME=aws01

DOCKER_TLS_VERIFY=1

DOCKER_CERT_PATH=/home/youruser/.docker/machine/machines/aws01
Connect to your newly provisioned docker host:
$ docker-machine ssh aws01
If you’ve gone through the setup successfully you should have a remote session established with your docker host as easy as this:
Welcome to Ubuntu 15.10 (GNU/Linux 4.2.0-34-generic x86_64)

* Documentation:https://help.ubuntu.com/

Get cloud support with Ubuntu Advantage Cloud Guest:

http://www.ubuntu.com/business/services/cloud

109 packages can be updated.

65 updates are security updates.

Last login: Mon Apr 18 05:28:12 2016 from 212.72.209.2

ubuntu@aws01:~$

 

Conclusion:

We just scratched the surface what’s possible with docker machine, but as with everything else getting the foundation right is essential and important step to be able to build on top of. For me,  it remains the easiest way to experience and play with docker.  In the next blog post I’ll be going through how to setup a private docker registry.

Talk to us now

Contact us