LXC (Linux Containers) is an OS-level virtualization method for running multiple isolated Linux systems (containers) on a single host, using one Linux kernel. Unlike full virtual machines, LXC containers share the host kernel and are lightweight, making them useful for development, testing, and isolated workloads. This guide shows how to install and use LXC on Ubuntu 20.04, then optionally add the LXC Web Panel for browser-based management.
Prerequisites
- Ubuntu 20.04 server or desktop with sudo access.
- Enough disk space for container root filesystems (a minimal Ubuntu container is typically a few hundred MB).
Install LXC
Install the LXC userspace tools and templates:
sudo apt update
sudo apt install -y lxc lxc-templates
Check that the host kernel supports LXC:
lxc-checkconfig
You should see required and optional kernel features; all “required” should be enabled.
Create an LXC container
LXC ships with ready-made templates. List them:
ls /usr/share/lxc/templates/
Create a container interactively (you’ll be prompted for distribution, release, and architecture):
sudo lxc-create --template download --name u1
# or
sudo lxc-create -n new-container -t ubuntu
To create non-interactively, pass distribution, release, and architecture on the command line (replace DISTRO-SHORT-CODENAME with e.g. focal for Ubuntu 20.04):
sudo lxc-create -t download -n u1 -- --dist ubuntu --release focal --arch amd64
# or short form
sudo lxc-create -t download -n u1 -- -d ubuntu -r focal -a amd64
List existing containers:
lxc-ls
Start and use the container
Start the container in the background (-d daemonizes):
lxc-start -n new-container -d
Attach to the container console (log in as root; exit with Ctrl+A then Q to detach):
lxc-console -n new-container
Inspect the container state:
lxc-info -n new-container
Start and stop (foreground vs background is controlled by whether you use -d):
lxc-start -n new-container
lxc-stop -n new-container
Pause and unpause
Pause (freeze) and resume the container:
lxc-freeze -n new-container
lxc-unfreeze -n new-container
Snapshots
Take a snapshot (the container should be stopped for a consistent snapshot):
lxc-stop -n new-container
lxc-snapshot -n new-container
List snapshots:
lxc-snapshot -L -n new-container
Restore a snapshot (e.g. snap0):
lxc-snapshot -r snap0 -n new-container
Delete a container
Stop the container, then destroy it (this removes the root filesystem):
lxc-stop -n new-container
lxc-destroy -n new-container
LXC Web Panel (optional)
LXC Web Panel is a web UI to create, start, stop, clone, and delete LXC containers from a browser.
Install (run as root or with sudo; review the script before piping to shell):
wget https://lxc-webpanel.github.io/tools/install.sh -O - | sudo bash
When installation finishes, open http://<your-server-ip>:5000 in a browser. Log in with the default credentials (admin / admin) and change the password after first login.
Update the panel later with:
wget https://lxc-webpanel.github.io/tools/update.sh -O - | sudo bash
If you access it remotely, allow port 5000 in your firewall (e.g. sudo ufw allow 5000/tcp && sudo ufw reload).
Verifying the setup
- LXC:
lxc-checkconfigshould show required kernel features enabled;lxc-lsshould list your containers. - Container: After
lxc-start -n new-container -d,lxc-info -n new-containershould show state “RUNNING”;lxc-console -n new-containershould give you a shell inside the container. - Web Panel: With the panel installed,
http://localhost:5000(or your server IP:5000) should show the login page.
Summary
You installed LXC and lxc-templates on Ubuntu 20.04, created containers with lxc-create (interactive or with --dist/--release/--arch), and used lxc-start, lxc-stop, lxc-console, lxc-info, lxc-freeze/lxc-unfreeze, lxc-snapshot, and lxc-destroy to manage them. Optionally, you added the LXC Web Panel for GUI management. For more automation and image-based workflows, consider LXD (the newer daemon and CLI built on LXC).