Linux containers part one


Linux containers are infrastructure for container projects

Some very useful, but slightly outdated, information on Stephane Graber’s site
Stephane is the LXD technical lead at Canonical Ltd.

LXD introduction
From that site: “LXD is written in Go, it’s free software and is developed under the Apache 2 license.”

All of the examples in this series are run in one or more Virtualbox VM’s using either Ubuntu Server or Debian

Worth noting that the Linux container software is fairly rapidly changing.
It has been my experience that many of the examples given online are outdated and do not apply to recent installs.
Notably, anyone suggesting using lxc- commands (e.g. lxc-ls) are definitely using an older version, all the lxc client commands are now available from a single executable, lxc.

Install

On a VM running Ubuntu Server 16.04 or greater lxc and lxd should already be installed, both the native and snap versions.
For Debian, lxc can be simply installed, e.g.

apt-get install -y lxd lxd-client lxd-tools criu lxc-templates
## lvm tools required for lvm pool
apt-get install -y thin-provisioning-tools

Of the two OS Ubuntu is preferred as it includes ZFS.
If you can’t use ZFS then BTRFS is the next best option as besides ZFS it also supports snapshots.
LXD will also work using LVM and plain directories but with reduced functionality.

After installing LXD the first job is to initialise the installation.
Note that at this point you will be configuring storage that will be used by LXD.
Separate disks are preferred for this, easy to arrange if you are using a virtual machine for testing.
Note also that the initialisation will only offer storage options supported on your machine.

$ lxd init
Do you want to configure a new storage pool (yes/no) [default=yes]?
Name of the new storage pool [default=default]:
Name of the storage backend to use (dir, btrfs, lvm) [default=btrfs]:
Create a new BTRFS pool (yes/no) [default=yes]?
Would you like to use an existing block device (yes/no) [default=no]?
Size in GB of the new loop device (1GB minimum) [default=15GB]: 10
Would you like LXD to be available over the network (yes/no) [default=no]? yes
Address to bind LXD to (not including port) [default=all]:
Port to bind LXD to [default=8443]:
Trust password for new clients:
Again:
Would you like stale cached images to be updated automatically (yes/no) [default=yes]?
Would you like to create a new network bridge (yes/no) [default=yes]?
What should the new bridge be called [default=lxdbr0]?
What IPv4 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
What IPv6 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
LXD has been successfully configured.

The first 6 options will cause creation of a new 10GB BTRFS storage pool using a loopback device.
Following network options will make LXD available over the network (internet if your machine is connected directly) protected by a password.
A network bridge will be created using the local NIC using IPV4 and V6 address ranges which will automatically be assigned (in the 10. range).

Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.