Introduction to LXD Container Hypervisor

Recently I was tasked to setup an internal documentation system. After looking at several options such as Mediawiki, Confluence, Twiki, etc, we decided to implement DokuWiKi. In past, my process would have been to spin up a new server, then install all the dependencies for DokuWiKi and then get the latest tarball to bring up DokuWiKi.

But hey, it’s 2017 and with all the Container wars in IT industry, me sticking to one app per server seems like a waste of resources. There are plenty of options in this area as well and some of the most common are Docker, LXC (Linux Containers) and LXD.

Ubuntu 16.04 which released in April 2016 comes built in with a Container Hypervisor called LXD (Lex-Dee as they call it). Instead of focusing on Performance difference between Docker and LXD, I decided to simply stick to this one and see how it performs.

I am writing down how I installed, configured both LXD and DokuWiKi on my server and I hope it help some of you guys as well. Please note that this article only applies to “Ubuntu 16.04”. 

LXD Containers


As per Stéphane Graber, Project Leader of LXC, LXD and LXCFS; LXD is a daemon which provides a REST API to drive LXC containers.

Please follow the steps below to Install, Configure and then use LXD to Launch and Manage containers.

  • Install LXD on Ubuntu by using following command.
sudo apt install lxd
  • In order to use LXD you first need to initialize it by issuing following command.
sudo lxd init
  • This command guides you through various options of configuration, such as File System to be used, Networking Protocol to be used, etc. Please see below for options I chose.
Name of the storage backend to use (dir or zfs) [default=zfs]: zfs
Create a new ZFS pool (yes/no) [default=yes]? no
Name of the existing ZFS pool or dataset: pool/filesystem
Would you like LXD to be available over the network (yes/no) [default=no]? no
Do you want to configure the LXD bridge (yes/no) [default=yes]? yes
Name of the Bridge Interface: lxdbr0
Do you want to setup IPv4 subnet? Yes
Random Subnet Selected : Press Ok
Enter new Subnet : 192.168.10.1
IPv4 CIDR mask : 24
First DHCP address : 192.168.10.2
Last DHCP Address : 192.18.10.254
Max DHCP clients : 252
Do you want to NAT IPv4 traffic : Yes
Do you want to setup IPv6 subnet ? No
Warning: Stopping lxd.service, but it can still be activated by:
 lxd.socket
LXD has been successfully configured.

  • Once configured you can launch a container by issuing following command. This will launch a Ubuntu 16.04 container and tag it as “dokuwiki”. When you run this command for the first time, it downloads the base image which will be used for creating containers.
lxc launch ubuntu:16.04 dokuwiki
  • You can list containers on your system by running following command.
lxc list

+----------+---------+----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------+---------+----------------------+------+------------+-----------+
| dokuwiki | RUNNING | 192.168.10.25 (eth0) | | PERSISTENT | 0 |
+----------+---------+----------------------+------+------------+-----------+

  • Connecting to a Container and running bash inside the container
lxc exec dokuwiki /bin/bash
root@dokuwiki:~#

Notice you are now inside the container and can run regular shell commands.

  • Some other useful commands are listed below.
----- Start Container -----
lxc start containername

----- Stop Container -----
lxc stop containername

----- Delete Container -----
lxc delete containername

----- File Manipulation on Container -----
lxc file pull containername/path-on-container dest-on-host
lxc file push source-on-host containername/path-on-container

I will keep on updating this page to add more details on LXD. I am also planning to add tutorials on creating variety of containers such as DokuWiki, Gitlab, Jenkins using LXD & NGINX as reverse proxy to the containers.

I would really appreciate if you could provide your thoughts on this post.

One thought on “Introduction to LXD Container Hypervisor

Leave a comment