The Missing Bit

Simple Containers
December 19, 2018
Updated: August 19, 2019

linux containers

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

I didn’t want to use a virtual machine because I wanted shared filesystems to be able to work on the project from Arch 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 Arch wiki, I stumbled onto systemd-nspawn which is basically systemd containers.

You just give it a directory and “voilĂ ” you have a working container.

Arch also provide a tool to bootstrap debian.

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

host# debootstrap --include=systemd-container stable 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.

If you wish to comment or discuss this post, just mention me on Mastodon or Twitter.

Related posts