Docker is an open source platform designed for system administrators and
developers to deploy applications. There are a number of tools around the
Docker ecosystem which make it easier to get started with Docker, one of them
is the recently released (but still in alpha): Docker Machine.
Docker Machine allows you to deploy Docker hosts using a simple command.
Typically, you would have to create a new virtual machine, install multiple
Docker components until you’re ready to provision new containers. With Docker
Machine, it’s a matter of a single command.
Installing Docker Machine
Docker Machine is a tool which is installed on your local machine which takes
care of deploying a new instance and installing Docker on it. It’s currently
still in alpha, but you can always download the latest release from GitHub.
Once you download the appropriate binary for your operating system, it’s best
to move it to
/usr/local/bin/ so that you can easily access the command again,
installing the latest release at the time of writing th is article (which is
v0.1.0-rc4) should look like this.
$ wget https://github.com/docker/machine/releases/download/v0.1.0-rc4/docker-machine_darwin-amd64 $ chmod +x docker-machine_darwin-amd64 $ mv docker-machine_darwin-amd64 /usr/local/bin/docker-machine
Configure Environment Variables
When Docker provisions a new instance, it can use the common OpenStack
environment variables for your credentials to reduce the number of command-line
arguments you have to provide and make it easier for you to use.
You can setup your credentials by logging into the CloudConsole control panel,
navigating to the “API Credentials” button and you’ll see them listed under the
openrc file section, they will be similar to the following:
export OS_TENANT_NAME="d433974b-859d-420f-ad6b-bbc7da546e5f" export OS_USERNAME="b569971a-9b81-4c3e-8cea-42f375c0592d" export OS_PASSWORD="D0AfrjJkMhVQl5ZHO5gIrftsjEtCH14FYqNahFNjku3CemmH" export OS_AUTH_URL="http://auth.api.thenebulacloud.com:5000/v2.0/" export OS_REGION_NAME="ca-ymq-1"
You can either save this in a file called
openrc and then calling it by
source openrc or you can simply run those commands in your shell
before moving on.
Create Docker Instance
Once you have all the correct information, you can proceed to create your new
Docker instance. You will need to provide a flavor and image ID when creating
this new instance, so we’ll use the
nova CLI commands to get it.
$ nova image-list | grep 'Ubuntu 14.04' $ nova flavor-list
With these commands, you’ll be able to find the Ubuntu image UUID and you can
select the flavor you wish to use. In our case, we’ll use the current Ubuntu
14.04 LTS image (uuid:
dc808930-9d49-4a27-b71a-77e12a3c5b54) and the
instance type (uuid:
$ docker-machine create -d openstack \ --openstack-flavor-id 8c6a8477-20cb-4db9-ad1d-be3bc05cdae9 \ --openstack-image-id dc808930-9d49-4a27-b71a-77e12a3c5b54 \ docker-1
The process will take a few minutes, it will provision a new instance in your
cloud account, install the latest release of Docker on it and store the required
information on your machine to access it using the Docker client. If you have
docker CLI installed, you will be able to manage it by using the
tool within Docker Machine.
$ $(docker-machine env docker-1) $ docker ps
Now, you can create new containers easily without having to SSH to the host as
well. All communication is encrypted using TLS to the remote Docker instance.
$ docker run -i -t ubuntu /bin/bash root@d2a0912ad721:/# ps auxf USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 1.0 0.0 18168 1924 ? Ss 22:49 0:00 /bin/bash root 14 0.0 0.0 15564 1100 ? R+ 22:49 0:00 ps auxf
You can now easily use Docker in any way you want, without having to login to
any other machine. In the future, we’ll add another article on how to use
Docker’s other new tool, Docker Swarm.