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-ubuntuLaunch a Debian 12 virtual machine.
lxc launch images:debian/12 my-debian-vm --vmLaunch a container and apply specific profiles.
lxc launch images:alpine/edge my-alpine -p default -p macvlanLaunch with direct resource configuration.
lxc launch images:ubuntu/24.04 web-server -c limits.cpu=2 -c limits.memory=1GiBViewing & Listing
View brief information for all instances.
lxc listFilter 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,tCommand Execution & Interaction
Get an interactive bash shell inside a container.
lxc exec my-ubuntu -- bashRun a single command, such as updating the package list.
lxc exec my-ubuntu -- apt updateGet console access to a virtual machine.
lxc console my-debian-vmLifecycle Management
Start an instance.
lxc start my-ubuntuStop an instance.
lxc stop my-ubuntuRestart an instance.
lxc restart my-ubuntuPause an instance (freeze its state).
lxc pause my-ubuntuDelete an instance (must be stopped first).
lxc delete my-ubuntuForce delete an instance (without stopping).
lxc delete my-ubuntu --forceFile Transfer
Push a single file to an instance.
lxc file push ./local.conf my-ubuntu/etc/nginx/nginx.confPull 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 listSearch for images containing "ubuntu" in the `images` remote.
lxc image search images:ubuntuImporting & 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.04Publish an existing instance as a new image.
lxc publish my-ubuntu --alias clean-ubuntuMaintenance
Create or modify an alias for an image.
lxc image alias create u24 my-ubuntu-24.04Delete a local image.
lxc image delete my-ubuntu-24.043. Network Configuration
Network Management
List all networks.
lxc network listShow detailed information for the default bridge network `lxdbr0`.
lxc network show lxdbr0Edit network configuration in interactive mode.
lxc network edit lxdbr0Instance Network Configuration
Set a static IPv4 address for instance `my-ubuntu`.
lxc config device set my-ubuntu eth0 ipv4.address 10.0.1.100Add a `macvlan` device to connect the container directly to the physical network.
lxc config device add my-ubuntu eth1 nic nictype=macvlan parent=eth0Set 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:804. Storage Management
Storage Pools
List all storage pools.
lxc storage listCreate a ZFS storage pool named `data`.
lxc storage create data zfsShow information about the `default` storage pool.
lxc storage info defaultStorage Volumes
Create a 10GB custom storage volume named `my-volume` in the `data` pool.
lxc storage volume create data my-volume size=10GiBAttach the storage volume `my-volume` to the instance `my-ubuntu` at `/mnt/data`.
lxc storage volume attach data my-volume my-ubuntu /mnt/dataList all storage volumes in the `data` storage pool.
lxc storage volume list data5. Configuration & Profiles
Profile Management
List all available profiles.
lxc profile listCreate a new profile named `webserver`.
lxc profile create webserverEdit the configuration of the `webserver` profile.
lxc profile edit webserverAdd the `webserver` profile to the instance `my-ubuntu`.
lxc profile add my-ubuntu webserverInstance-Specific Configuration
Set an instance to start automatically on host boot.
lxc config set my-ubuntu boot.autostart trueAdd 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=/dataView all configurations for instance `my-ubuntu` (including applied profiles).
lxc config show my-ubuntu --expanded6. Snapshots, Backups & Migration
Snapshots
Create a snapshot named `pre-update` for the instance `my-ubuntu`.
lxc snapshot my-ubuntu pre-updateRestore an instance to a specific snapshot state.
lxc restore my-ubuntu pre-updateDelete a snapshot.
lxc delete my-ubuntu/pre-updateBackup & Restore
Export an instance to a compressed backup file.
lxc export my-ubuntu my-ubuntu-backup.tar.gzImport an instance from a backup file.
lxc import my-ubuntu-backup.tar.gzMoving & Copying
Rename an instance locally.
lxc move my-ubuntu new-nameCopy an instance to create a new one locally.
lxc copy my-ubuntu my-ubuntu-clone7. Information Display
View LXD server status and configuration information.
lxc infoView detailed information for a specific instance `my-ubuntu`, including snapshots and resource usage.
lxc info my-ubuntuMonitor LXD event logs in real-time.
lxc monitorView the LXD daemon's logs.
lxc monitor --type=loggingView a list of recent operations.
lxc operation list8. Remotes & Clustering
Remote Management
List all configured remote servers.
lxc remote listAdd a new remote LXD server.
lxc remote add my-remote 192.168.1.100List 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-copyClustering
List all member nodes in the cluster.
lxc cluster listCreate an instance on a specific cluster node `node1`.
lxc launch images:ubuntu/24.04 c3 --target node19. Useful Shortcuts
Information Query
Quickly get the IP address of an instance.
lxc list my-ubuntu -c 4 --format csv | cut -d' ' -f1List the names of all running instances.
lxc list --format csv -c n --filter status=runningView resource usage for all instances (C:CPU, m:Memory, N:Network).
lxc list -c n,s,C,m,NBulk 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; doneCleanup & 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 deleteWarning: 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 {}