LXD on Ubuntu Quick Start

This guide focuses on the most essential commands and operations to help you get started with LXD in the shortest time possible.

Default environment: Ubuntu 22.04/24.04 | LXD version: snap (officially recommended)

1. What is LXD & Use Cases

LXD is a modern, secure, and powerful system-level container and lightweight VM manager, with core technologies being LXC (for containers) and QEMU (for virtual machines).

Core Difference from Docker

LXD is more like a "lightweight VM manager". The instances it creates have complete operating system environments (independent init, systemd, SSH services, etc.), making you feel like managing a real physical machine or cloud host. Docker focuses more on "packaging and running single processes or applications", with container lifecycle tied to application processes, pursuing ultimate lightness and portability.

2. Installation & Initialization

2.1 Installation

First, confirm your system has snap installed and enabled.

snap version

Install LXD via snap (officially recommended method, auto-updates and includes all dependencies).

sudo snap install lxd snap info lxd

2.2 Initialization

After installation, run the interactive initialization wizard to configure LXD.

sudo lxd init

The wizard will guide you through configuring storage pools, networks, image servers, etc. For beginners, accepting defaults is usually fine.

3. Basic Concepts Quick Reference

Instance
Generic term for containers and virtual machines.
Image
Template for creating instances, e.g., ubuntu/22.04.
Profile
Reusable configuration set for network, storage, resource limits, etc.
Storage Pool
Determines where instance disks are stored and backend driver (zfs/btrfs/dir).

4. Quick Start (Containers & VMs)

4.1 Create and Enter Container

lxc image list images: ubuntu lxc launch images:ubuntu/22.04 myct lxc list lxc exec myct -- bash

4.2 Create and Use VM

lxc launch images:ubuntu/22.04/cloud myvm --vm lxc console myvm --type=console lxc file push ./local.txt myct/root/ lxc file pull myct/etc/os-release .

4.3 Basic Lifecycle Management

lxc stop myct lxc start myct lxc restart myct lxc delete myct lxc info myct

5. Essential Commands Summary

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
lxc stop/start/restart [instance] Stop/start/restart instance
lxc snapshot [instance] [name] Create snapshot for instance
lxc file push/pull Transfer files between host and instance

6. Next Steps

📚 Learn More

Explore advanced features like clustering, profiles, and automation.

View FAQ →

đŸ› ī¸ Practice

Set up development environments and experiment with different configurations.

View Commands →

🚀 Deploy

Use LXD for production workloads and CI/CD pipelines.

Official Docs →