What is LXD? Overview
LXD is not just another Docker. It's a system container manager designed to provide a complete, persistent Linux system environment that feels almost identical to physical machines or VMs, but with minimal overhead.
Linux Kernel
(Namespaces, Cgroups)
LXC
Low-level container library
LXD
System Container Manager
Docker
Application Container Manager
Simply put, LXD is the "super manager" of LXC, providing a powerful REST API and clean command-line tools that greatly simplify the management of system containers and virtual machines.
Core Features
Ultimate Performance
Near bare-metal performance with second-level startup, far exceeding traditional VMs.
High-Density Deployment
Extremely low memory footprint, easily run hundreds of containers on a single host.
Unified Management
One set of commands to manage both system containers and VMs, simplifying operations.
Advanced Snapshots
Instant creation and restoration of instance states, supporting advanced storage features like ZFS.
Device Passthrough
Directly assign physical devices like GPUs, USB, and disks to instances.
Flexible Networking
Support for various network modes like bridge, macvlan, easily integrating into complex network environments.
Technical Comparison: LXD vs. VMs vs. Docker
LXD fills the gap between traditional virtual machines and application containers. It has both the complete system experience of VMs and the lightweight efficiency of containers. The table below clearly shows their differences.
Feature | LXD System Containers | Traditional VMs | Docker App Containers |
---|---|---|---|
Isolation Level | Process-level (shared kernel) | Complete isolation (separate kernel) | Process-level (shared kernel) |
Startup Speed | Seconds | Minutes | Seconds |
Resource Overhead | Very low (MB-level) | High (GB-level) | Low (MB-level) |
Management Experience | Like managing a complete server | Like managing a physical machine | Managing single application processes |
Persistence | Persistent, stateful | Persistent, stateful | Usually stateless, ephemeral |
Best Scenarios | Dev environments, CI/CD, multi-service hosting | Running different OS, legacy apps | Microservices, packaging single apps |
Core Use Cases
Development & Testing Environments
Quickly create isolated development and testing sandboxes that are consistent with production environments, avoiding the "works on my machine" embarrassment.
CI/CD Pipelines
Leverage its high performance and API-driven features to provide clean, dynamic, reproducible environments for automated build, test, and deployment.
Lightweight Virtualization & Hosting
As a lightweight alternative to traditional VMs, host multiple services and applications, achieving higher server resource utilization.
Quick Start
Getting started with LXD on Ubuntu is very simple. With just a few commands, you can launch your first system container.
1 Install LXD
$ sudo snap install lxd
2 Initialize Configuration
$ lxd init --auto
The `--auto` parameter uses default configuration for quick initialization, suitable for beginners.
3 Launch Your First Container
# Launch an Ubuntu 22.04 container
$ lxc launch images:ubuntu/22.04 my-first-container
# Enter the container shell
$ lxc exec my-first-container -- bash
Common Commands Cheat Sheet
Master these core commands to easily manage your LXD instances.
Command | Description |
---|---|
lxc launch [image] [name] | Create and start a new instance |
lxc list | List all instances |
lxc exec [instance] -- [command] | Execute command in instance (e.g., `bash`) |
lxc stop / start / restart [instance] | Stop / start / restart instance |
lxc delete [instance] | Delete an instance |
lxc snapshot [instance] [snapshot-name] | Create snapshot for instance |
lxc restore [instance] [snapshot-name] | Restore instance from snapshot |
lxc file push/pull ... | Transfer files between host and instance |
Frequently Asked Questions (FAQ)
It depends on your needs. If you need a complete, persistent Linux environment for development, testing, or hosting multiple services (like a lightweight VM), choose LXD. If you need to package, distribute, and run single stateless applications (microservices), choose Docker. They're not mutually exclusive and can even be used together.
Very secure. LXD leverages multiple Linux kernel security features like user namespaces, AppArmor, and Seccomp to strictly limit container privileges. By default, LXD containers run in unprivileged mode, so even the root user inside the container cannot affect the host system.
Yes. This is a common advanced use case. You need to enable nested virtualization support in a special "privileged" LXD container. This is useful for creating isolated Docker development environments or testing Docker itself. Command: `lxc config set my-docker-container security.nesting true`
Yes, LXD is a completely free open-source project, primarily sponsored and developed by Canonical (Ubuntu's parent company). You can use it freely in personal projects and commercial environments.