Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (40 sloc) 1.51 KB
layout title ref lang date tags
Linux containers with systemd-nspawn
2016-11-28 22:27:49 +0200
linux virt systemd

When I needed specific linux distribution on a modern linux host, I used to utilize schroot. More robust solution would be to use LXC. However the same page suggests systemd-nspawn as an alternative. So I tried it the other day when needed to prepare CentOS 7 for my work.

Setup is easy: just obtain root file system tree. Needed to work around inaccessible /tmp/.X11-unix within the container --- bound directory explicitly from non-tmpfs. Created launch script to launch the system conveniently:


cur_dir=`readlink -f $(dirname ${BASH_SOURCE[0]})`

xhost +local:

# Note that --bind /tmp/.X11-unix doesn't actually preserve sockets,
# pass them through /w

sudo systemd-nspawn \
    -D $cur_dir/centos \
    -b \
    -n \
    --bind /w \
    --bind /home/sakhnik

The result is impressive. The system "boots" into login terminal:

![Booted CentOS 7]({{ site.url }}/assets/2016-11/systemd-nspawn.png)

I used virtual network ethernet connection in the container with systemd-networkd:

![Network configuration]({{ site.url }}/assets/2016-11/systemd-nspawn2.png)

So far, so good. Let's see later how usable the container is.