We have set up LXD on either our personal computer or on the cloud (like DigitalOcean and Scaleway). Actually, we can even try LXD online for free at https://linuxcontainers.org/lxd/try-it/
What shall we do next?
Commands through “lxc”
Below we see a series of commands that start with lxc, then we add an action and finally we add any parameters. lxc here is the program that does the communication with the LXD service and performs the actions that we request. That is,
lxc action parameters
There are also a series of commands that are specific to a type of object. In that case, we add in the the object type and continue with the action and the parameters.
lxc object action parameters
List the available containers
Let’s use the list action, which lists the available containers.
ubuntu@myvps:~$ lxc list Generating a client certificate. This may take a minute... If this is your first time using LXD, you should also run: sudo lxd init To start your first container, try: lxc launch ubuntu:16.04 +------+-------+------+------+------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+-------+------+------+------+-----------+ ubuntu@myvps:~$
List the locally available images for containers
Let’s use the image object, and then the list action, which lists the available (probably cached) images that are hosted by our LXD service.
ubuntu@myvps:~$ lxc image list +-------+-------------+--------+-------------+------+------+-------------+ | ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE | +-------+-------------+--------+-------------+------+------+-------------+ ubuntu@myvps:~$
There are no locally available images yet, so the list is empty.
List the remotely available images for containers
ubuntu@myvps:~$ lxc image list ubuntu: +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | p (5 more) | 6b6fa83dacb0 | yes | ubuntu 12.04 LTS amd64 (release) (20160627) | x86_64 | 155.43MB | Jun 27, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | p/armhf (2 more) | 06604b173b99 | yes | ubuntu 12.04 LTS armhf (release) (20160627) | armv7l | 135.90MB | Jun 27, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ ...
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | x (5 more) | f452cda3bccb | yes | ubuntu 16.04 LTS amd64 (release) (20160627) | x86_64 | 138.23MB | Jun 27, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | x/arm64 (2 more) | 46b365e258a0 | yes | ubuntu 16.04 LTS arm64 (release) (20160627) | aarch64 | 146.72MB | Jun 27, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | x/armhf (2 more) | 22f668affe3d | yes | ubuntu 16.04 LTS armhf (release) (20160627) | armv7l | 148.18MB | Jun 27, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ ...
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | | 4c6f7b94e46a | yes | ubuntu 16.04 LTS s390x (release) (20160516.1) | s390x | 131.07MB | May 16, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ | | ddfa8f2d4cfb | yes | ubuntu 16.04 LTS s390x (release) (20160610) | s390x | 131.41MB | Jun 10, 2016 at 12:00am (UTC) | +--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+ ubuntu@myvps:~$
Show information for a remotely available image for containers
ubuntu@myvps:~$ lxc image info ubuntu:x Uploaded: 2016/06/27 00:00 UTC Expires: 2021/04/21 00:00 UTC Properties: aliases: 16.04,x,xenial os: ubuntu release: xenial version: 16.04 architecture: amd64 label: release serial: 20160627 description: ubuntu 16.04 LTS amd64 (release) (20160627) Aliases: - 16.04 - 16.04/amd64 - x - x/amd64 - xenial - xenial/amd64 Auto update: disabled ubuntu@myvps:~$
Here we can see the full list of aliases for the 16.04 image (x86_64). The simplest of all, is x.
Life cycle of a container
Here is the life cycle of a container. First you initialize the image, thus creating the (stopped) container. Then you can start and stop it. Finally, in the stopped state, you may select to delete it.
ubuntu@myvps:~$ lxc init ubuntu:x mycontainer Creating mycontainer Retrieving image: 100% ubuntu@myvps:~$ lxc image list +-------+--------------+--------+---------------------------------------------+--------+----------+------------------------------+ | ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE | +-------+--------------+--------+---------------------------------------------+--------+----------+------------------------------+ | | f452cda3bccb | no | ubuntu 16.04 LTS amd64 (release) (20160627) | x86_64 | 138.23MB | Jul 22, 2016 at 2:10pm (UTC) | +-------+--------------+--------+---------------------------------------------+--------+----------+------------------------------+
ubuntu@myvps:~$ lxc list +-------------+---------+------+------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+------+------+------------+-----------+ | mycontainer | STOPPED | | | PERSISTENT | 0 | +-------------+---------+------+------+------------+-----------+ ubuntu@myvps:~$ lxc start mycontainer ubuntu@myvps:~$ lxc list +-------------+---------+------+-----------------------------------------------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+------+-----------------------------------------------+------------+-----------+ | mycontainer | RUNNING | | 2607:f2c0:f00f:2770:216:3eff:fe4a:ccfd (eth0) | PERSISTENT | 0 | +-------------+---------+------+-----------------------------------------------+------------+-----------+
ubuntu@myvps:~$ lxc list +-------------+---------+-----------------------+-----------------------------------------------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+-----------------------+-----------------------------------------------+------------+-----------+ | mycontainer | RUNNING | 10.200.214.147 (eth0) | 2607:f2c0:f00f:2770:216:3eff:fe4a:ccfd (eth0) | PERSISTENT | 0 | +-------------+---------+-----------------------+-----------------------------------------------+------------+-----------+ ubuntu@myvps:~$ lxc exec mycontainer -- /bin/bash root@mycontainer:~# uname -a Linux mycontainer 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux root@mycontainer:~# exit exit ubuntu@myvps:~$ lxc list +-------------+---------+-----------------------+-----------------------------------------------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+-----------------------+-----------------------------------------------+------------+-----------+ | mycontainer | RUNNING | 10.200.214.147 (eth0) | 2607:f2c0:f00f:2770:216:3eff:fe4a:ccfd (eth0) | PERSISTENT | 0 | +-------------+---------+-----------------------+-----------------------------------------------+------------+-----------+ ubuntu@myvps:~$ lxc stop mycontainer ubuntu@myvps:~$ lxc list +-------------+---------+------+------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+------+------+------------+-----------+ | mycontainer | STOPPED | | | PERSISTENT | 0 | +-------------+---------+------+------+------------+-----------+ ubuntu@myvps:~$ lxc delete mycontainer ubuntu@myvps:~$ lxc list +------+-------+------+------+------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+-------+------+------+------+-----------+ ubuntu@myvps:~$ lxc image list +-------+--------------+--------+---------------------------------------------+--------+----------+------------------------------+ | ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE | +-------+--------------+--------+---------------------------------------------+--------+----------+------------------------------+ | | f452cda3bccb | no | ubuntu 16.04 LTS amd64 (release) (20160627) | x86_64 | 138.23MB | Jul 22, 2016 at 2:10pm (UTC) | +-------+--------------+--------+---------------------------------------------+--------+----------+------------------------------+ ubuntu@myvps:~$
Some tutorials mention the launch action, which does both init and start. Here is how the command would have looked like,
lxc launch ubuntu:x mycontainer
We are nearing the point where we can start doing interesting things with containers. Let’s see the next blog post!
1 comments
1 pings
Nice, thanks for the overview.
[…] posts we saw how to set up LXD on a DigitalOcean VPS, how to set up LXD on a Scaleway VPS, and how the lifecycle of an LXD container looks […]