Ubuntu 17.04: 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.

#!/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 debian/stretch image and run it. IP address is assigned to container.

$ 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
5:eth0@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
state UP group default qlen 1000
    link/ether 00:16:3e:3c:1d:23 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.26.102.87/24 brd 10.26.102.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fd42:6bb1:545e:554b:216:3eff:fe3c:1d23/64 scope global
mngtmpaddr dynamic
       valid_lft 3596sec preferred_lft 3596sec
    inet6 fe80::216:3eff:fe3c:1d23/64 scope link
       valid_lft forever preferred_lft forever