LXD Common Commands Cheat Sheet

A curated list of core LXD commands for developers and administrators, packed with shortcuts to help you manage containers and VMs efficiently.

1. Instance Management

Creation & Launch

Launch an Ubuntu 24.04 container named my-ubuntu.

lxc launch images:ubuntu/24.04 my-ubuntu

Launch a Debian 12 virtual machine.

lxc launch images:debian/12 my-debian-vm --vm

Launch a container and apply specific profiles.

lxc launch images:alpine/edge my-alpine -p default -p macvlan

Launch with direct resource configuration.

lxc launch images:ubuntu/24.04 web-server -c limits.cpu=2 -c limits.memory=1GiB

Viewing & Listing

View brief information for all instances.

lxc list

Filter names using a regular expression.

lxc list "web-*"

Customize output columns (n: name, s: status, 4: IPv4, P: profiles, t: type).

lxc list -c n,s,4,P,t

Command Execution & Interaction

Get an interactive bash shell inside a container.

lxc exec my-ubuntu -- bash

Run a single command, such as updating the package list.

lxc exec my-ubuntu -- apt update

Get console access to a virtual machine.

lxc console my-debian-vm

Lifecycle Management

Start an instance.

lxc start my-ubuntu

Stop an instance.

lxc stop my-ubuntu

Restart an instance.

lxc restart my-ubuntu

Pause an instance (freeze its state).

lxc pause my-ubuntu

Delete an instance (must be stopped first).

lxc delete my-ubuntu

Force delete an instance (without stopping).

lxc delete my-ubuntu --force

File Transfer

Push a single file to an instance.

lxc file push ./local.conf my-ubuntu/etc/nginx/nginx.conf

Pull a single file from an instance.

lxc file pull my-ubuntu/var/log/syslog .

Recursively push an entire directory.

lxc file push -r ./my-app my-ubuntu/opt/

2. Image Management

Finding & Listing

List locally downloaded images.

lxc image list

Search for images containing "ubuntu" in the `images` remote.

lxc image search images:ubuntu

Importing & Exporting

Copy an image from a remote to local storage and set an alias.

lxc image copy images:ubuntu/24.04 local: --alias my-ubuntu-24.04

Publish an existing instance as a new image.

lxc publish my-ubuntu --alias clean-ubuntu

Maintenance

Create or modify an alias for an image.

lxc image alias create u24 my-ubuntu-24.04

Delete a local image.

lxc image delete my-ubuntu-24.04

3. Network Configuration

Network Management

List all networks.

lxc network list

Show detailed information for the default bridge network `lxdbr0`.

lxc network show lxdbr0

Edit network configuration in interactive mode.

lxc network edit lxdbr0

Instance Network Configuration

Set a static IPv4 address for instance `my-ubuntu`.

lxc config device set my-ubuntu eth0 ipv4.address 10.0.1.100

Add a `macvlan` device to connect the container directly to the physical network.

lxc config device add my-ubuntu eth1 nic nictype=macvlan parent=eth0

Set up port forwarding: forward host port 8080 to container port 80.

lxc config device add my-ubuntu http-proxy proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:80

4. Storage Management

Storage Pools

List all storage pools.

lxc storage list

Create a ZFS storage pool named `data`.

lxc storage create data zfs

Show information about the `default` storage pool.

lxc storage info default

Storage Volumes

Create a 10GB custom storage volume named `my-volume` in the `data` pool.

lxc storage volume create data my-volume size=10GiB

Attach the storage volume `my-volume` to the instance `my-ubuntu` at `/mnt/data`.

lxc storage volume attach data my-volume my-ubuntu /mnt/data

List all storage volumes in the `data` storage pool.

lxc storage volume list data

5. Configuration & Profiles

Profile Management

List all available profiles.

lxc profile list

Create a new profile named `webserver`.

lxc profile create webserver

Edit the configuration of the `webserver` profile.

lxc profile edit webserver

Add the `webserver` profile to the instance `my-ubuntu`.

lxc profile add my-ubuntu webserver

Instance-Specific Configuration

Set an instance to start automatically on host boot.

lxc config set my-ubuntu boot.autostart true

Add a disk device to an instance, mounting the host's `/data` directory to the container's `/data`.

lxc config device add my-ubuntu data-share disk source=/data path=/data

View all configurations for instance `my-ubuntu` (including applied profiles).

lxc config show my-ubuntu --expanded

6. Snapshots, Backups & Migration

Snapshots

Create a snapshot named `pre-update` for the instance `my-ubuntu`.

lxc snapshot my-ubuntu pre-update

Restore an instance to a specific snapshot state.

lxc restore my-ubuntu pre-update

Delete a snapshot.

lxc delete my-ubuntu/pre-update

Backup & Restore

Export an instance to a compressed backup file.

lxc export my-ubuntu my-ubuntu-backup.tar.gz

Import an instance from a backup file.

lxc import my-ubuntu-backup.tar.gz

Moving & Copying

Rename an instance locally.

lxc move my-ubuntu new-name

Copy an instance to create a new one locally.

lxc copy my-ubuntu my-ubuntu-clone

7. Information Display

View LXD server status and configuration information.

lxc info

View detailed information for a specific instance `my-ubuntu`, including snapshots and resource usage.

lxc info my-ubuntu

Monitor LXD event logs in real-time.

lxc monitor

View the LXD daemon's logs.

lxc monitor --type=logging

View a list of recent operations.

lxc operation list

8. Remotes & Clustering

Remote Management

List all configured remote servers.

lxc remote list

Add a new remote LXD server.

lxc remote add my-remote 192.168.1.100

List all instances on the remote server named `my-remote`.

lxc list my-remote:

Copy a remote instance `my-remote:c1` to local.

lxc copy my-remote:c1 local:c1-copy

Clustering

List all member nodes in the cluster.

lxc cluster list

Create an instance on a specific cluster node `node1`.

lxc launch images:ubuntu/24.04 c3 --target node1

9. Useful Shortcuts

Information Query

Quickly get the IP address of an instance.

lxc list my-ubuntu -c 4 --format csv | cut -d' ' -f1

List the names of all running instances.

lxc list --format csv -c n --filter status=running

View resource usage for all instances (C:CPU, m:Memory, N:Network).

lxc list -c n,s,C,m,N

Bulk Operations

Stop all running instances.

lxc list -c n --format csv --filter status=running | xargs -r -I {} lxc stop {}

Delete all stopped instances.

lxc list -c n --format csv --filter status=stopped | xargs -r -I {} lxc delete {}

Run updates in all running Ubuntu containers.

for c in $(lxc list images:ubuntu -c n --format csv --filter status=running); do lxc exec $c -- apt update \&\& apt upgrade -y; done

Cleanup & Maintenance

Clean up all unused local image caches.

lxc image list --format json | jq -r '.[] | select(.auto_update == false and (.aliases | length) == 0) | .fingerprint' | xargs -r lxc image delete

Warning: This is a destructive operation

This command will immediately and permanently delete all LXD instances on your system, and it cannot be undone. Please double-check before executing.

Force delete all instances.

lxc list -c n --format csv | xargs -r -I {} lxc delete --force {}