Skip to content

Developing With Docker (Day 1)

TL;DR: Over this series of articles I’m going to try and build up and develop for node.js in a re-usable continer (vm) without polluting my host machine with various versions of node.js, mongodb, etc.

For a while I’ve been using vagrant and chef/puppet to develop in sandboxed environments without pulling dependency hell onto my host computer. In fact my host computers (laptop and desktop) are now pretty vanilla linux mint systems with editors and git installed. I actually version what I have on these boxes using puppet.

However, I have a few problems with vagrant for development. I don’t know if docker will solve these but we’ll see.

  • Host/Guest shared filesystems have lots of permissions issues on linux and even more on windows. The differences between usernames and root/non-root cause real issues when developing code on your host but building / generating on a VM.
  • Guest VM’s use up ram. This isn’t an issue on desktops now a days with > 24gb ram easily accessible. But it’s a big deal on laptops which are still averaging 8gb.
  • Not easy to checkpoint VMs or rebuild from a midway point. I may be missing something here with vagrant, but it’d be nice to have a good known base and restart from there.
  • Have to be online to get updates or build your box.

That said, I really like the reproduceable system/machine configurations that vagrant and chef/puppet allow you to have. I also really like being able to just checkout out a project and “vagrant up”, and have a sandboxed environment ready to go (with some caveats).

Getting Started

You should install the latest docker. Follow the instructions on the site. I’m not going to update this to keep in sync with docker (which is moving quickly).


Coming from vagrant I expected some form of smart configuration file. Docker doesn’t really do that. I was also expecting redo-ability, like you get with puppet or chef. You don’t get that either. What you do get is a very simple command by command syntax which executes line by line. It’ll execute everything in the file every single time the build is run. So hopefully you’re a bashmaster.

Here’s the Dockerfile that I use to create a box with node.js installed on it:

from ubuntu:12.10

# update system and install dependencies

run apt-get update
run apt-get install -y python2.7 python build-essential wget

# get and build node

run cd /tmp && wget
run cd /tmp && tar -xzvf /tmp/node-v0.10.15.tar.gz
run cd /tmp/node-v0.10.15 && ./configure --prefix=/usr && make && make install

So what does this do?

from ubuntu:12.10

This says start with the ubuntu:12.10 base image. This comes from the base docker boxes. For those familiar with vagrant, this is like

run apt-get update

This runs “apt-get update” as root. In fact everything in the Dockerfile is run as root.

run apt-get install -y python2.7 python build-essential wget

This installs python 2.7 (and it’s symlinks), build-essential (make/gcc), and wget (used to pull node)

run cd /tmp && wget

Download node into /tmp

run cd /tmp && tar -xzvf /tmp/node-v0.10.15.tar.gz

Extract node into /tmp

run cd /tmp/node-v0.10.15 && ./configure --prefix=/usr && make && make install

Build and install node.

Building The box container

Now we need to build this machine. You can clone this repository from, or you can just save the Dockerfile into a new directory.

To build we run:

docker build -t u1210_node .

In the directory containing the dockerfile. This will build a new container and if it succededs, it will tag it as u1210_node (so that we can use it later with a “from” directive).

. is actually the path to the directory containing the Dockerfile, so you could run this from anywhere. And containers are referenced by ID/tag not by path so context doesn’t matter at the moment. This will change when we try to share files with the container.

Using The Image

Not that we’ve built the image successfully, we can get a shell into it with

docker -i -t u1210_node /bin/bash

This will launch an interactive terminal (-i) allocating a pseudo tty (-t) with bash as the program (/bin/bash) into the container with the tag u1210_node.

Try it. You can play around all you want.

Next time I’m going to try and work up a Dockerfile iteratively with all the cruft I need to do app development with node.


  1. WordPress › Error

    There has been a critical error on this website.

    Learn more about troubleshooting WordPress.