Adding a package to boot2docker

Docker is seeing rapid adoption among the software development world. So far it seems to me a very nice way to make software installation much less painful, but there is still plenty of room for improvement.

If you’re running Linux then you can stop reading now. Docker is an abstraction layer over Linux Containers (LXC), they’ve also created a repository where pre-defined containers can be found – you can even add your own. LXC is cool stuff, but it does mean Docker runs Linux.

Windows and OSX users need to use boot2docker, a Tiny Core Linux virtual machine that has just enough stuff to run docker. This is a fine solution but often when people ask about missing tools inside of boot2docker, the answer is to install a container that has the tools you want and run inside of that container. Things quickly start to feel like Inception.

Boot2docker is based on Tiny Core Linux, so you can use the tce-load utility to install additional components if needed. So say we wanted to run Perl:

$ tce-load -wi perl5

You can sniff around the repository to figure out what packages are available.

There is documentation on adding a persistent partition to your boot2docker setup. This is useful if you want to run the tce-load every time you run without having to type it in each time. Getting this setup is a little bit fiddly, and if we’re clever we can do something a bit cooler.

Let’s build a custom boot2docker.iso file! The build process is nicely documented. We can use a Dockerfile to create our own iso with the packages we want.

Before we start, you will want to make sure that your boot2docker is running with enough resources. The default should be 2048MB which should work, you will also need enough disk space on /var/lib/docker/aufs inside boot2docker.  If you have problems consider changing your configuration.

Create a Dockerfile with the following contents:

FROM boot2docker/boot2docker

# Append indicator this is modified image
RUN echo "\nMy modified boot2docker.iso\n" >> $ROOTFS/etc/motd

# Install perl5
RUN curl -L -o /tmp/perl5.tcz $TCL_REPO_BASE/tcz/perl5.tcz && \
unsquashfs -f -d $ROOTFS /tmp/perl5.tcz && \
rm -rf /tmp/perl5.tcz

# build the iso
RUN /make_iso.sh
CMD ["cat", "boot2docker.iso"]

Then follow the boot2docker.iso build process.

$ sudo docker build -t my-boot2docker-img .
$ sudo docker run --rm my-boot2docker-img > boot2docker.iso

The FROM is used to declare the base image we want to start from. We’re building our new container on this base.

The RUN directive is executed against the current image at build time. In this case we can’t use tce-load since we’re not actually running Tiny Core Linux at this point, we’re running against the docker image we are building. This is why we’re doing the installation of perl manually. I based the installation from the boot2docker DockerFile.

The last two steps “build the iso” are lifted directly from the same boot2docker Dockerfile, these are the steps required to actually create the iso file.

Figuring out how to run the boot2docker.iso I’ll leave as an exercise for the reader.

Musings

Wow, 2014 seems to have zoomed by and I only manged to make 3 posts to this blog. There was some (non spam) comment activity from folks who’d found articles I’d written that were useful to them – getting feedback is always nice!

I was quite busy with my work on JavaScript runtimes (specifically Node/V8). You can check out the IBM DeveloperWorks page and grab the product of my team’s efforts. Folks that are keen to see code – should check my GitHub account and you’ll find ports of V8 for PowerPC and s390/zLinux.

Late in the year I switched roles at moved to the team that is delivering container runtimes on the IBM Bluemix cloud. We managed to rush something out the door for DockerCon Europe. It even made the IBM www front page:

Still lots to do in this rapidly evolving space, so it should be an interesting 2015 (which might keep me away from doing side projects).

Despite the fact I didn’t manage to turn out very many posts here, I was tinkering away in my limited spare time. From the top of my head: I fixed an XBox360, did lots of 3D printing (including some 2 color prints); modified my Printrbot to be more reliable; replaced some capacitors in a failing DSL modem to fix it; charged a FitBit using a hacked USB cable.. maybe I’ll try to post up a few of those as I do have notes (each of these posts takes a couple of hours usually).

So there you go, I’ve managed to break the ice and start writing here again. I have some work related stuff that I’ll be posting up here soon and hope to document some of the tinkering projects I’ve done (and have queued up) as well.