Getting started with Docker

Docker is fantastic wrapper around Linux Containers with a brilliant collaboration workflow. If you do any kind of virtualisation you should seriously consider it.

What is Docker?

Docker is a wrapper around Linux Containers with some additional goodies thrown in. It allows you to run processes in a virtualised, sandboxed environment on different flavours of Linux that share the same underlying kernel. This means that you can run a Node.js process on Gentoo, a Ruby process on Fedora, and a PHP process on Ubuntu. These processes share the same physical hardware and Linux kernel of the Host machine but each has its own sandboxed filesystem and network interfaces.

For a good introduction to Docker and Linux Containers watch this video:

The anaolgy with shipping containers is very striking here. If you can make the container for your application a standard it becomes much easier and more efficient to scale it. Horizonatal scaling, where you scale out across machines rather than up on hardware means that being able to spin up new instances of your application is more important than ever.

How is it different from full virtualisation?

The traditional model is to use full virtualisation. You might buy a beefy server and use a tool like kvm to split the server into virtualised servers. You can use a tool like puppet to build and maintain the servers. This allows you to build a stack for your applications updating configurations when necessary. In this scenario it is the application that is portable and not the server. With Linux Containers and Docker you have a wrapper that describes everything that is needed to run the application. It becomes trivial to bring up new instances each being an exact replica of the previous one. Furthermore because Linux Containers are relatively lightweight the time to bring up a new docker instance is trivial compared to bringing up a fully virtualised server.

Show me an example

The quickest way to play around with Docker from any platform is to install Virtualbox and Vagrant. This page on the Docker site describes how to quickly get a docker image up and running after that.

To ensure that host machine ports are forwarded to docker ports within vagrant start vagrant with

FORWARD_DOCKER_PORTS=1 vagrant up

You can ssh to the box with

vagrant ssh

You should see that docker installed by running

sudo docker

A killer feature of Docker is that you can share images that you have created with other people with a simple workflow. For example it could be that someone has already solved your problem. You can search for images that you might be interested in with the following command. In this example we look for wordpress images.

docker search wordpress

To keep things simple lets install a base ubuntu image

sudo docker pull ubuntu

Then you can run the standard docker hello world example against this image

sudo docker run ubuntu /bin/echo hello world

You will notice that the command runs almost instantly. You can follow through creating a daemon and how to attach to logs in the Hello World example in the documentation.

That’s nice but what can it really do?

Let’s suppose you want a Wordpress instance. Just do this

sudo docker pull jbfink/wordpress
sudo docker run -d -p 49002:80 jbfink/wordpress:latest

On your host machine open your browser at http://localhost:49002. There it is. Amazing.

Because it is a container you can be very certain that it will run reliably through docker. The start up time is minimal too.

Don’t like how Wordpress has been configured? You can fork it and make it to your own liking.

With a bit of light scripting you could start a Wordpress as a Service site. Starting to see the power of Docker? The fact that you can share these images means that it becomes a hyper powerful tool for deploying and developing software.

Want to create your own image? Just decribe what you want in a Dockerfile. Here’s a moderately complex one for the Wordpress image.

Usages

Docker is an awesome tool for sharing environments and deploying new instances of images quickly and with minimal effort.

Much of the buzz around Docker has been around PaaS services. But docker makes it simple to build images for continuous integration agents, images for cloud hosting providers, shared development environments and frankly is just a plain brilliant way to collaborate.

At pebble {code} we are super impressed with this project. We are looking over the fence at our kvm setup and it is looking distinctly long in the tooth.

Tags

Can you help make this article better? You can edit it here and send me a pull request.

See Also