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:
| |
Check that the host kernel supports LXC:
| |
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:
| |
Create a container interactively (you’ll be prompted for distribution, release, and architecture):
| |
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):
| |
List existing containers:
| |
Start and use the container
Start the container in the background (-d daemonizes):
| |
Attach to the container console (log in as root; exit with Ctrl+A then Q to detach):
| |
Inspect the container state:
| |
Start and stop (foreground vs background is controlled by whether you use -d):
| |
Pause and unpause
Pause (freeze) and resume the container:
| |
Snapshots
Take a snapshot (the container should be stopped for a consistent snapshot):
| |
List snapshots:
| |
Restore a snapshot (e.g. snap0):
| |
Delete a container
Stop the container, then destroy it (this removes the root filesystem):
| |
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):
| |
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:
| |
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).