LXD のイメージを使って、systemd-nspawn のコンテナを起動する
前置き
いろいろなコンテナの規格がありますが、普段 LXD と systemd-nspawn を使っています。 systemd の方がコンセプト的に好きなのですが、LXD に比べるとまだユーザ体験では劣っている様に思えます。 まず、systemd-nspawn 用の起動イメージ配布されていないようだったので、LXDのイメージを転用してみます。
試した環境は Ubuntu 16.04 です。
install
download image
lxcコマンドを使ってイメージをダウンロードします。
$ mkdir xenial
$ lxc lxc image export images:ubuntu/xenial ./xenial
Output is in ./xenial
$ ls -l xenial
total 82M
-rw-rw-r-- 1 xx xx 668 Feb 4 20:47 lxd.tar.xz
-rw-rw-r-- 1 xx xx 82M Feb 4 20:48 rootfs.tar.xz
extract image
ダウンロードしたイメージを展開します。
start container
下記のコマンドで上記までで用意したrootfsでコンテナを起動できます。
$ sudo systemd-nspawn -D rootfs
Spawning container rootfs on /home/xx/xenial/rootfs.
Press ^] three times within 1s to kill container.
Failed to create directory /home/xx/xenial/rootfs/sys/fs/selinux: Read-only file system
Failed to create directory /home/xx/xenial/rootfs/sys/fs/selinux: Read-only file system
root@rootfs:~#