Precisely Docker

Have been playing around with docker for sometime now. Had some trouble with getting docker working out of the box in many cases. But once I get it working there is no looking back, if you have not tried out docker and have not heard of what docker can do, its time I tell you. Docker is this cool command line client that helps to pull, launch, bundle and push docker images. Well not all the those things in one command but you could still chain them into one.

Docker is this spectacular utility with which you could, turn any machine into a hypervisor, of sorts, without even burning a tiny drop of your midnight oil. And its actually so lightweight you would hardly see it running or burning up your system resources, cause it uses linux kernel’s very cool namespaces and cgroups, and turns them on their head to provide you very simple commands to create linux containers full with networking and other resource isolations.

Docker is growing fast and so is its the documentation. It has a vibrant community ready to address all your queries asap. The official documentation could be found at http://docker.io, and the project is hosted at https://github.com/dotcloud/docker. What follows is my getting started with docker.

I working on vagrant Ubuntu VM as my host. As mentioned in my earlier blog I have installed vagrant and got an Ubuntu “precise64” box running. Just a recap to get this running.

~/vagrant # mkdir docker-box
~/vagrant # cd docker-box
~/v/docker-box # vagrant init

Edit the the Vagrant file and replace,

  config.vm.box = "base"

with

  config.vm.box = "precise64"

Now boot up the instance.

~/v/docker-box # vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise64'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
~/v/docker-box # vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)
  • Documentation: https://help.ubuntu.com/
    Welcome to your Vagrant-built virtual machine.
    Last login: Fri Sep 13 18:44:30 2013 from 10.0.2.2
    vagrant@precise64:~$

Now that you are inside a running a ubuntu box we need to get the requirements to run docker, satisfied. Its suggested that docker needs to run at least the linux kernel 3.8 underneath. But the precise64 box we just got onto does not seem to satisfy that.

vagrant@precise64:~$ sudo su -
root@precise64:~# uname -r
3.2.0-23-generic

First up lets get the kernel upgraded, for this make sure the backports are enable in the apt sources. And then update the package sources

root@precise64:~# apt-get update

And now install the new linux kernel, this ensures the basic requirement for the docker is satisfied.

root@precise64:~# apt-get install linux-headers-generic-lts-raring linux-generic-lts-raring linux-image-generic-lts-raring

Docker depends on the AUFS[1], a union filesystem. This filesystem used to keep the standard container pretty lean, as the root file systems of multiple containers is layered on top of one another, and uses a copy-on-write to provide induvidiality to container partitions. Raring kernel that we installed in the above step does provide AUFS as module. So make your to have this module loaded, which not loaded by default.

root@precise64:~# modprobe aufs

Now you would not want to do this, manually, every single time machine loads, right? So just add “aufs” to the /etc/modules.We have reached safe stage where we could install docker. But before that we should tell apt where to get docker from.

root@precise64:~# sh -c "curl https://get.docker.io/gpg | apt-key add -" #install curl before doing this.
root@precise64:~# sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
root@precise64:~# apt-get update
root@precise64:~# apt-get install lxc-docker

That should have installed docker. Couple of things to note before taking docker for a ride. Docker installation would have created the a bridge for the use with docker, named “docker0”, and a service named docker[2] would have started.

Now is the time to take docker for a spin. For that lets pull a basic ubuntu from the docker image repo

root@precise64:~# docker pull ubuntu
Pulling repository ubuntu
8dbd9e392a96: Download complete
b750fe79269d: Download complete
27cf78414709: Download complete

Be patient if you have a slow connection. Wait if you have a faster one :). In a while you should see this.

Now for the moment we all been waiting for. The raise of the docker container.

root@precise64:~# docker run -i -t ubuntu /bin/bash
root@a0108596ec4b:/#

You are now inside a container. Now for that container to come up it did not take that long, right? What just happend? Docker created a linux container full with a filesystem and network interface set up, and gave it to you as fully isolated server to do your piece. Really? Yeah! Fire up another ssh to the vagrant vm and see for yourself.

root@precise64:~# brctl show
bridge name    bridge id		STP enabled	interfaces
docker0		8000.b2eb07949957	no		vethv1qAdp
lxcbr0		8000.000000000000	no		
root@precise64:~# ip addr show vethv1qAdp 
6: vethv1qAdp: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master docker0 state UP qlen 1000
    link/ether b2:eb:07:94:99:57 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::b0eb:7ff:fe94:9957/64 scope link 
       valid_lft forever preferred_lft forever
root@precise64:~# docker ps
ID                  IMAGE               COMMAND             CREATED             STATUS              PORTS
a0108596ec4b        ubuntu:12.04        /bin/bash           30 minutes ago      Up 30 minutes                       
root@precise64:~# lxc-list
RUNNING
  a0108596ec4b2fcbb77374b580dc33f9e2fddb5d8225eefeacaba6f29b71023e

FROZEN

STOPPED

Well now you might ask, “Is docker production ready?”. Please, for those who are obsessed with 1.x versions, it is not, still 0.6 something. But if you can wield a tool effectively it is ready to be used, as mentioned here.

My exploration has not stopped… its precisely the beginning.

[1] AUFS is not accept into the standard linux kernel. But another union filesystem called overlayfs makes the cut. So I would not be suprised if AUFS replaced with the use of overlayfs.

[2] Interesting thing to note here is that docker is essentally a service as well as command utility.

Show Comments