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.
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:
# 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
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
FROM is used to declare the base image we want to start from. We’re building our new container on this base.
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.