The Missing Bit

Simple Containers
December 19, 2018

While working with openembeded, I needed specific version of some software (well, not specific, but not the bleeding edge archlinux has).

I didn’t want to use a virtual machine because I wanted shared filesystems to be able to work on the project from archlinux and compile it using a stable distribution.

At first I thought of Docker, but my last experience with it was not pleasant. I didn’t need complicated network setup, I wanted direct access to the filesystem and simplicity.

While reading the excellent archlinux wiki, I stumbled onto systemd-nspawn which is basically systemd containers.

You just give it a directory and “voiĆ ” you have a working container.

Archlinux also provide a tool to bootstrap debian.

So, just do (mostly copied from archlinux wiki):

sudo debootstrap --include=systemd-container stable debian/ http://deb.debian.org/debian/ (where debian/ is the root directory of the container)

After that, spawn the container, first with only the shell to set a root password:

host# systemd-nspawn -D debian
guest# passwd
guest# logout

Then start the container with init:

host# systemd-nspawn -b -D debian

More info on the wiki.

With this, I can manage guest filesystem from the host (using ZFS), I created a user in the guest with the same uid as my host user, so I can just work on the project from the host.