Fedora 29: コンテナ技術のLXDをインストールする

LXDをインストールしてコンテナを立ち上げます。

1 LXDをインストールする

snapをインストールします。

#!/bin/sh -e

# Install snapd.
sudo dnf install -y snapd
sudo systemctl start snapd.seeded.service
while [ "$(systemctl is-active snapd.seeded.service)" != "active" ]; do
  sleep 1;
done
sudo reboot

LXDをインストールします。

#!/bin/sh -e

# Install lxd.
# Disable SELinux temporary because it prevent lxd installation.
sudo setenforce 0
sudo snap install lxd
sudo gpasswd -a hiroom2 lxd
sudo reboot

2 LXDを初期化する

以下のスクリプトはLXDを初期化します。

#!/bin/sh


# Would you like to use LXD clustering? (yes/no) [default=no]: no
# Do you want to configure a new storage pool? (yes/no) [default=yes]: yes
# Name of the new storage pool [default=default]: default
# Name of the storage backend to use (dir, lvm, zfs) [default=zfs]: dir
# Would you like to connect to a MAAS server? (yes/no) [default=no]: no
# Would you like to create a new network bridge? (yes/no) [default=yes]: yes
# What should the new bridge be called? [default=lxdbr0]: lxdbr0
# What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”)
# [default=auto]: auto
# What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”)
# [default=auto]: none
# Would you like LXD to be available over the network? (yes/no)
# [default=no]: no
# Would you like stale cached images to be updated automatically? (yes/no)
# [default=yes] yes
# Would you like a YAML "lxd init" preseed to be printed? (yes/no)
# [default=no]: no

# Initialize LXD with NAT network.
lxd waitready
cat <<EOF | lxd init
no
yes
default
dir
no
yes
lxdbr0
auto
none
no
yes
no
EOF

3 コンテナを立ち上げる

debian/stretchのイメージをダウンロードして立ち上げることができました。 IPアドレスが割り振られています。

$ lxc launch images:debian/stretch debian
<snip>
$ lxc exec debian ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
4: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
state UP group default qlen 1000
    link/ether 00:16:3e:29:1e:7d brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:fe29:1e7d/64 scope link tentative
       valid_lft forever preferred_lft forever