LXD commands

June 4, 2016 by

As noted in my previous article Setting up a test LXD environment on Ubuntu 16.04, LXD is basically the next generation of LXC with a lot of enhancements. As such, LXD uses mainly the same commands as LXC, as you can see below.

This is a collection of commands that I frequently use to get things done with LXD. I’ll be adding more commands as I come across new and useful ones.

List downloaded images

ubuntu@lxd01:~$ lxc image list
+--------+--------------+--------+----------------------------------------+--------+---------+-----------------------------+
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               |  ARCH  |  SIZE   |         UPLOAD DATE         |
+--------+--------------+--------+----------------------------------------+--------+---------+-----------------------------+
| alpine | 2c42822a17d7 | no     | Alpine edge (amd64) (20160603_17:50)   | x86_64 | 2.65MB  | Jun 3, 2016 at 7:59pm (UTC) |
+--------+--------------+--------+----------------------------------------+--------+---------+-----------------------------+
| xenial | b5dd1999b9fa | no     | Ubuntu xenial (amd64) (20160603_03:49) | x86_64 | 77.53MB | Jun 3, 2016 at 3:10pm (UTC) |
+--------+--------------+--------+----------------------------------------+--------+---------+-----------------------------+

List containers and state

ubuntu@lxd01:~$ lxc list
+--------+---------+----------------------+----------------------------------------------+------------+-----------+
| NAME   |  STATE  |        IPV4          |                     IPV6                     |    TYPE    | SNAPSHOTS |
+--------+---------+----------------------+----------------------------------------------+------------+-----------+
| alpine | STOPPED |                      |                                              | PERSISTENT | 0         |
+--------+---------+----------------------+----------------------------------------------+------------+-----------+
| xenial | RUNNING | 10.182.123.17 (eth0) | fde8:e26:2b3a:9cce:216:2eff:fe38:23e0 (eth0) | PERSISTENT | 0         |
+--------+---------+----------------------+----------------------------------------------+------------+-----------+

Stop a container

ubuntu@lxd01:~$ lxc stop <containerName>

Snapshot a container

ubuntu@lxd01:~$ lxc snapshot <containerName> <snapshotName>

View container info

ubuntu@lxd01:~$ lxc info <containerName>

Output:

Name: xenial
Architecture: x86_64
Created: 2016/06/03 19:17 UTC
Status: Running
Type: persistent
Profiles: default
Pid: 3314
Ips:
  eth0: inet    10.182.123.17   vethACG27X
  eth0: inet6   fde8:e26:2b3a:9cce:216:2eff:fe38:23e0   vethACG27X
  eth0: inet6   fe80::216:3eff:fe38:23e0    vethACG27X
  lo:   inet    127.0.0.1
  lo:   inet6   ::1
Resources:
  Processes: 47
  Disk usage:
    root: 633.77MB
  Memory usage:
    Memory (current): 349.99MB
    Memory (peak): 360.20MB
  Network usage:
    eth0:
      Bytes received: 39.23MB
      Bytes sent: 8.52MB
      Packets received: 20771
      Packets sent: 12919
    lo:
      Bytes received: 0 bytes
      Bytes sent: 0 bytes
      Packets received: 0
      Packets sent: 0
Snapshots:
  snap-20160603-1821 (taken at 2016/06/04 01:21 UTC) (stateless)

Delete a container

ubuntu@lxd01:~$ lxc delete <containerName>

Networking

VPN

Allow for OpenVPN inside of a container:

ubuntu@lxd01:~$ lxc config device add <containerName> tun unix-char path=/dev/net/tun

Leave a Reply