Hello Techies, this tutorial will guide you through the process of installing LXD on Ubuntu 24.04 LTS. We’ll also cover how to create containers using the lxc
command and access the LXD UI.
What is LXD?
LXD is a container manager built on top of LXC (Linux Containers), offering a user experience similar to virtual machines but with the efficiency of containers. LXD leverages Linux kernel features like cgroups and namespaces to provide isolation and resource management. Unlike Docker containers which are stateless by default, LXC containers persist data even after they are stopped. LXD acts as a management layer, simplifying the deployment and scaling of LXC-based containers.
Prerequisites
Before you begin, make sure you have the following:
- A system running Ubuntu 24.04.
- A local user account with
sudo
privileges. - An active internet connection.
- Basic command-line knowledge.
Let’s proceed with the installation steps. Log in to your Ubuntu 24.04 LTS system and follow the instructions below.
How to set up LXD on Ubuntu
Method 1: Installing LXD using Snap
Step 1: Update Your System
It is important to update your system’s package lists and upgrade installed packages to their latest versions. This ensures you have the latest security patches and improvements.
$ sudo apt update
$ sudo apt upgrade -y
Step 2: Reboot Your System
After installing the available updates, it’s recommended to reboot the system to apply any kernel updates.
$ sudo reboot
Step 3: Install LXD via Snap
The recommended way to install LXD on Ubuntu is through snap
, the universal package manager for Linux.
$ sudo snap install lxd
Step 4: Add your Local User to LXD Group
Add your local user to the lxd
group to execute lxc
commands without sudo
.
$ sudo usermod -aG lxd $USER
$ newgrp lxd
$ id
$ lxc list
Step 5: Initialize LXD
Initialize LXD to configure it for your environment.
$ lxd init
Answer the questions as follows:
- When it asks about clustering, choose
no
(unless you’re setting up a cluster). - For storage, it’s recommended to say
yes
to a new storage pool. - The
dir
backend is fine for beginners. - Say
yes
to a network bridge. - Choose
yes
to make LXD server available over the network. - For address to bind lxd , use default.
- Port to bind lxd is
8443
.
Step 6: Allow LXD Network Bridge in Firewall
If you have the firewall (ufw) enabled, allow traffic on the lxdbr0
network bridge.
$ sudo ufw allow in on lxdbr0
$ sudo ufw route allow in on lxdbr0
$ sudo ufw route allow out on lxdbr0
$ sudo ufw reload
Step 7: Create Your First Container
Launch a container to test your LXD setup. The syntax to launch a container is as follows:
$ lxc launch remote:image containername
For example, launch an Ubuntu 24.04 container named demo-container
.
$ lxc launch ubuntu:24.04 demo-container
Step 8: Verify Container Creation
Run lxc list
command to view the container.
$ lxc list
Step 9: Manage LXC Containers
Here are some basic commands to manage your LXC containers:
Access the console of container.
$ lxc exec demo-container -- bash
Stop a container:
$ lxc stop demo-container
Start a container:
$ lxc start demo-container
Delete a container:
$ lxc delete demo-container
Step 10: Access LXD Web UI
During LXD initialization, we allowed the LXD server over the network. Access the LXD web UI using your system’s IP address and port 8443
. Ensure port 8443
is allowed in the firewall.
$ sudo ufw allow 8443/tcp
$ sudo ufw reload
In the web browser, type the following URL:
https://<IP Address of Your Ubuntu System>:8443
Accept the risk and continue because we are using self-signed certificates.
Click on ‘Create a new certificate
’, it will take us to the following page.
Click on Generate
and Choose Skip
for adding password to the certificate.
Download the crt
and pfx
files on your system. Transfer crt file to your Ubuntu system and run the following command.
$ lxc config trust add lxd-ui.crt
Head back to browser, follow the screen instructions to import pfx file in your browser.
After importing the pfx file, refresh browser, click on “Use an existing certificate
”
It will take us to the following screen.
Generate the token from your Ubuntu system, run
$ lxc config trust add --name lxd-ui
Copy the token and paste it in the import field and then click on Import
. It takes us now to dashboard as shown below.
That concludes this guide. Hopefully, you found it helpful.