Getting started with Docker

Table of contents

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?

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.

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

Recent Posts

Using HashiCorp Vault with LDAPHow to use HashiCorp Vault to setup an LDAP backed secret store with read-only access for users in groups and read-write access for specific users

Linux and Unix xargs command tutorial with examplesTutorial on using xargs, a UNIX and Linux command for building and executing command lines from standard input. Examples of cutting by character, byte position, cutting based on delimiter and how to modify the output delimiter.

Copy a file in GoHow to copy a file in Go. The ioutil package does not offer a shorthand way of copying a file. Instead the os package should be used.

About the author

George Ornbo is a hacker, futurist, blogger and Dad based in Buckinghamshire, England.