How to Use Ubuntu Server lxd for System Container Management

When deploying applications on Ubuntu Server, the modern standard is to use Docker. However, Docker is an application container manager designed to run a single process (like an Nginx daemon or a MySQL instance). If you need an entirely separate operating system environment—complete with its own networking stack, init system (systemd), and cron daemon—but you don’t want the massive CPU and memory overhead of running a full Virtual Machine (like KVM or VMware), you need a system container. On Ubuntu, the premier tool for managing system containers is LXD.

What is LXD?

LXD (pronounced “Lex-Dee”) is a next-generation system container manager developed by Canonical. It sits on top of LXC (Linux Containers) and provides a REST API and a highly intuitive command-line interface. A container spun up with LXD feels exactly like a lightweight virtual machine. You can SSH into it, install packages via apt, and run background services, but because it shares the host’s kernel, it boots in less than a second and consumes practically zero idle RAM.

Step 1: Initialize LXD

On modern Ubuntu Server installations, the LXD snap package is often pre-installed. However, before you can spin up containers, you must run the initialization wizard to configure the storage backend and virtual networking.

sudo lxd init

The wizard will ask you a series of questions. For a basic setup, you can safely press Enter to accept the default answers for almost all of them, which will:

  • Create a local storage pool (usually using the ZFS or Btrfs filesystem for snapshot support).
  • Create a virtual network bridge (lxdbr0) so your containers can access the internet.
  • Enable NAT so the containers share the host’s public IP address.

Step 2: Launch Your First Container

To create and start a new container, you use the lxc launch command, followed by the image name and the name you want to give the container.

lxc launch ubuntu:22.04 webserver-01

LXD will contact the official Ubuntu image server, download the minimal root filesystem for Ubuntu 22.04, unpack it, and instantly boot the container. The entire process takes seconds.

Step 3: Manage Container State

To see a list of all your running containers, their IP addresses, and their current state, run:

lxc list

You will see webserver-01 listed as RUNNING, along with the internal IPv4 address it received from the lxdbr0 bridge.

To gracefully shut down the container (which sends a standard ACPI shutdown signal to the container’s systemd daemon):

lxc stop webserver-01

Step 4: Execute Commands Inside the Container

You do not need to install an SSH server inside the container to manage it. LXD provides a direct console attachment mechanism.

To get a root bash shell inside your running container:

lxc exec webserver-01 -- /bin/bash

Your terminal prompt will change to root@webserver-01:~#. You are now “inside” the container. You can run apt update, install Apache, modify configuration files, and exit back to the host by typing exit.

If you just want to run a single command without opening an interactive shell, you can append it directly:

lxc exec webserver-01 -- apt install nginx -y

Step 5: Snapshots and Backups

Because LXD uses advanced storage backends like ZFS, taking a snapshot of a container is instantaneous and consumes no extra disk space until data changes.

lxc snapshot webserver-01 pre-upgrade-backup

If you accidentally destroy the web server configuration, you can instantly roll back time:

lxc restore webserver-01 pre-upgrade-backup

By leveraging LXD, administrators can pack dozens of completely isolated, fully functional Linux environments onto a single physical server without the crushing performance penalties of traditional hardware virtualization.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.