In this tutorial, we’ll install LXD, configure our system to run LXC containers and initialize LXD on Alpine Linux. It should work on all platforms where LXD/LXC is supported (x86_64, ARM64, and more).
Alpine Linux is “an independent, non-commercial, general purpose Linux distribution designed for power users who appreciate security, simplicity and resource efficiency”. It’s incredibly lightweight and can be really useful for containers and virtual machines, as both a host and as a guest. Due to it’s small size, it’s able to run on everything from Qotom Firewall Appliances and MicroServers to Threadripper based workstations.
LXD is a “next generation system container manager”, which offers “a user experience similar to virtual machines but using Linux containers instead”. Unlike Docker, Kubernetes and similar, LXD is well suited for running system containers (full OS) at near bare metal speeds.
This article assumes you have Alpine Linux installed and running on a node already.
To use LXD on Alpine Linux, we’ll need to use the
edge branch (development tree). Replace the repositories in
$ sudo echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories $ sudo echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories $ sudo echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
apk cache and “upgrade” the system to
$ sudo apk update $ sudo apk upgrade
Install LXD using
$ sudo apk add lxd
Enable and start the
$ sudo rc-update add lxd $ sudo rc-service lxd start
We’ll need to enable and start the
$ sudo rc-update add cgroups $ sudo rc-service cgroups start
$ sudo echo "session optional pam_cgfs.so -c freezer,memory,name=systemd,unified" >> /etc/pam.d/system-login
Add user and group idmaps to LXC config:
$ sudo echo "lxc.idmap = u 0 100000 65536" >> /etc/lxc/default.conf $ sudo echo "lxc.idmap = g 0 100000 65536" >> /etc/lxc/default.conf
root (and other users as well)
$ sudo echo "root:100000:65536" >> /etc/subuid $ sudo echo "root:100000:65536" >> /etc/subgid
Finally, initialize LXD:
$ sudo lxd init # --auto
That should be it! You should now have a fully operational LXD instance. If you selected to initialize an LXD cluster, you can now join your other nodes to the cluster following the instructions on the LXD documentation! 📦😀