Menu

Docker : The Good Parts

I have been playing with Docker1 for a while. Initially, I had been using it like a hypervisor - spin up containers, play around with them, and shut them down. But in the past few days, I have recognised two very useful utilities of docker, that make life easier.

Docker as a deployment tool

This past week, I have been trying to deploy some of the projects I have worked on over the last two years. Each of these projects was different from the others: One was in Node.js, another was in Django, yet another in plain Python. I wanted them all to be running forever, didn’t want one to affect the others, and wanted them to be resistant to failure on account of changes to the environment in the server box. A perfect use case for docker.

Using docker to create a deployment environment involves writing a Dockerfile. Dockerfiles use a simple DSL which allows you to automate the steps you would normally manually take to create an image. Think of it as a make utility for deployment. The advantage of using docker is that it is portable; ie, the same container that you build and test on your laptop can run at scale, anywhere; in production, on VMs, bare metal, OpenStack clusters, public clouds etc.

Docker as an application sandbox

This is something that isn’t obvious on first thought. I remember that when I first heard about CoreOS, I had no idea how it would work. CoreOS is a minimal distro that contains just a Linux kernel and systemd and the root partition is completely read-only. It uses docker as a package manager to run applications on top of it. That means every user application will run in its own Linux container.2

I have seen a lot of projects in Github that I found really interesting, but kept away from trying out because of the complexity of their setup. First you have to do this, then that … If there were a simple Dockerfile, that built the complete setup, then a single command would suffice. A great example for this is StackEdit, the markdown editor used to write this document. I wanted to have a local copy as I wanted to use it even I was offline. I found their Dockerfile in Github 3 , so all I needed to do was build a container, and run it as a daemon. I don’t need to worry about the version of node, nor of the dependencies nor anything else. If it’s worked for them, it’ll work for me. As simple as that!

Another container I’m running is that of octopress. All my attempts to setup octopress in my local system were failing for some unknown reason, so I wrote a simple Dockerfile4 to set it up. I now have a completely sandboxed octopress setup, that I can use for any number of octopress blogs without needing to install everything again. The instructions to do the same will be provided in the next blog entry.

Have you found additional use cases for docker? Is there anything wrong about all that I’ve said above? If so, let’s discuss it in Hacker news