Useful LXD commands
List available containers
1
2
3
| lxc image list ubuntu: # ubuntu: is officially supported image source
lxc image list images: # images: is an unsupported source
lxc image alias list images: # lists user-friendly names
|
Launch a container
This creates and starts a container.
1
2
3
| lxc launch ubuntu:14.04 CONTAINERNAME # image and container names are optional
lxc launch ubuntu:14.04/armhf armcont # specific architecture
lxc launch images:alpine/3.3/amd64 # unsupported images: source
|
Create container
Without starting it.
1
2
3
| lxc init images:alpine/3.3/amd64 alpinecont
lxc copy CONTAINER1 CONTAINER2 # clone
lxc delete alpinecont [--force] # --force if it is running
|
Start/stop after creating it
1
2
3
4
| lxc start alpinecont
lxc stop alpinecont [--force] # --force if it doesn't want to stop
lxc restart alpinecont [--force]
lxc pause alpinecont # SIGSTOP to all container processes
|
List local containers
1
2
3
4
| lxc list
lxc list --columns "nsapt" # name, status, arch, PID of init, type
lxc list security.privileged=true # filter for properties
lxc info CONTAINERNAME # detailed info about one container
|
Available columns for the list command
1
2
3
4
5
6
7
8
9
10
| 4 - IPv4 address
6 - IPv6 address
a - Architecture
c - Creation date
n - Name
p - PID of the container's init process
P - Profiles
s - State
S - Number of snapshots
t - Type (persistent or ephemeral)
|
Rename
1
| lxc move CONTAINERNAME NEWNAME
|
Configuration
Config changes are effective immediately, even if container is running.
1
2
3
4
5
6
| export VISUAL=/usr/bin/vim
lxc config edit CONTAINERNAME # launches editor
lxc config set CONTAINERNAME KEY VALUE # change a single config item
lxc config device add CONTAINERNAME DEVICE TYPE KEY=VALUE
lxc config show [--expanded] CONTAINERNAME
Configuration settings can be saved as **profiles**.
|
Enter the container
1
2
3
| lxc exec CONTAINERNAME -- PROGRAM OPTIONS
lxc exec CONTAINERNAME sh
lxc exec CONATINERNAME --env KEY=VALUE PROGRAM # environment variable
|
This command runs the program in all the namespaces and cgroups of the container. The program must exist inside the container.
Access container files
1
2
3
| lxc file pull CONTAINERNAME/etc/passwd /tmp/mypasswd
lxc file push /tmp/mypasswd CONTAINERNAME/etc/passwd
lxc file edit CONTAINERNAME/etc/passwd
|
Snapshots
1
2
3
4
5
6
| lxc snapshot CONTAINERNAME SNAPNAME # SNAPNAME is optional; default name snap*X*
lxc restore CONTAINERNAME SNAPNAME # resets the container to snapshot
lxc copy CONTAINERNAME/SNAPNAME NEWCONTAINER # new container from snapshot
lxc delete CONTAINERNAME/SNAPNAME
lxc info CONTAINERNAME # lists snapshots among other info
lxc move CONTAINERNAME/SNAPNAME CONTAINERNAME/NEWSNAPNAME # rename snapshot
|