It's been a big week for Docker, a relatively new linux container platform. It's only Tuesday and they have announced a production ready release, have held their first conference and revamped their image index into the Docker Hub. Docker has also managed to garner support from Red Hat, Open Stack, Google, AWS, and Ubuntu.

What is Docker?

So, why all the fuss? To understand that, we need to understand what Docker does. Docker is a virtualization platform, but instead of heavyweight virtual machines Docker relies on lighter-weight virtual containers that are managed by a single operating system's kernel. In the case of Docker the linux kernel is the kernel doing the virtualization. Each container runs with its own filesystem, its own process group, and its own virtual network connection. Containers are not a new idea, but the time is ripe for them as they have less overhead than full virtual machines, but with many of the benefits.

However, I do not think the main benefit is necessarily in the technology, but in the standardization that Docker brings. Docker containers are supported in Elastic Beanstalk, and App Engine will be supporting the standard soon. This means it will soon be possible to write a Dockerized app and run it without changes on potentially many cloud platforms.

Great, How do I start?

There is great documentation available, and you can install Docker on your system fairly easily. In this article, however, I will show you how to get up and running quickly using AWS. I wont start with Elastic Beanstalk however, as it's easier to get started in an EC2 instance.

First thing you will want to do is generate an EC2 key pair. To do this follow the steps below:

  1. Go to the EC2 Console.
  2. Select the region you wish to use in the upper right-hand corner of the screen. I am using US West (Oregon), also known as us-west-2.
  3. Click the Key Pairs option on the left of the screen, under "Network & Security".
  4. Click the Blue Create Key Pair button.
  5. Name the key pair something simple like "docker" and click Create.
  6. Be sure to save the private key file. You will not be given another opportunity to download it.

Now that you have a key pair, it's time to create the server. To help I have created a Cloudformation template which you can use to provision the server.

To provision the server follow the steps below.

  1. Save the template on your computer: docker_server.cfn.json
  2. Go to the Cloudformation Console.
  3. Select the same region as you did for the keypair in the upper right-hand corner of the screen.
  4. Select Create Stack under the "Actions" menu, or click the Create New Stack button.
  5. Select a stack name, such as "DockerServer".
  6. Select "Upload a template to Amazon S3" and choose the template downloaded above.
  7. Click Next
  8. Select the Parameters for the template. In this case you should select the following:

    1. The size of your EBS Drive. Docker images can take up some space, so I recommend not being too stingy. I will select 20 Gigabytes for the example.
    2. The EC2 instance type. Since this is a demo, I will choose t1.micro.
    3. The EC2 key name. Choose the key you created above. Cloudformation parameters
  9. Click Next

  10. The next screen does not require any additional input, click Next again.
  11. Review the parameters and then click Create.

You will not have to wait as Amazon provisions the instance. The cloudformation console will keep you apprised of events and status. In addition to the instance, the stack creates a new security group with the description "Docker Server Security Group." You can view and modify this security group in the "Security Groups" portion of the EC2 Console.

Once the stack is created, you should be able to select the created stack in the Cloudformation console and select "Outputs" from the detail view in the lower half of the screen. The outputs should display a server address and the security group ID as shown below:

Cloudformation outputs

Note: It may take a few minutes after the image is created to update the operating system and install docker. Be sure to give it some time.

Diving In

Now that the instance is up and running, you can just ssh right into it and start playing. From my mac I use the command

ssh -i docker.pem [email protected]

and I've connected.

Before you begin, use the command

sg docker

to switch into the docker group. This will allow you to issue Docker commands without changing to root.

Now try the command docker version and you should get output something like this:

Client version: 0.9.1
Go version (client): go1.2.1
Git commit (client): 3600720
Server version: 0.9.1
Git commit (server): 3600720
Go version (server): go1.2.1
Last stable version: 1.0.0, please update docker

Version 0.9.1? This is the package that ships with ubuntu 14.04 LTS, which is the server I provisioned. See this post to find out how to painlessly set up Docker 1.0 under Ubuntu. Hopefully soon they will update to the latest version, but this version will be fine for running through the tutorial, and taking your first steps.

To get started try

docker pull ubuntu

which will download the ubuntu images. Then you can execute the traditional Hello World in a container by running

docker run -i -t ubuntu echo "Hello World!"

This command creates a container from the latest ununtu image, runs the echo command, then stops the image. If you use the command

docker ps -a

you can still see the image, and you can delete it with the docker rm command.

What next?

Now that you have a place to experiment, I recommend you read Dockerizing Applications and Working with Containers, and be sure to check out the Docker Hub to get some official and community containers to build your application stack.

When you are done experimenting, you can delete the server and its security group by going to the Cloudformation Console, selecting the stack we created, and pressing the Delete Stack button.

i