ElementaryOS 0.4: Install LXD for container

This article will describe installing LXD and running containers.

Table of Contents

1 Install LXD

The following script will install LXD with apt.

#!/bin/sh

set -e

sudo apt install -y lxd lxd-client lxd-tools zfsutils-linux criu

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

# Add user to lxd group.
sudo gpasswd -a "${USER}" lxd

# Reboot for updating group.
sudo reboot

2 Run container

This can download linux image and run it. IP address is assigned to container.

$ lxc launch images:fedora/26 fedora
<snip>
$ lxc exec fedora ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
group default qlen 1000
    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:77:a8:e6 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:fe77:a8e6/64 scope link tentative
       valid_lft forever preferred_lft forever