It’s now time to start using our LXD.
First, let’s make sure the client can connect to the daemon, by running
lxc list
The output should be similar to
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 |
+------+-------+------+------+------+-----------+
which shows there are no running containers.
Let’s now launch our first container:
lxc launch ubuntu:16.04
The output will be something like this:
Creating stirring-beagle
Starting stirring-beagle
This will download the official Ubuntu 16.04 LTS (Xenial Xerus) image and launch a container with it.
If a container name is not provided (like in this case), a random one will be generated.
Let’s check that our container is indeed running with lxc list
:
+-----------------+---------+-----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-----------------+---------+-----------------------+------+------------+-----------+
| stirring-beagle | RUNNING | 10.147.177.171 (eth0) | | PERSISTENT | 0 |
+-----------------+---------+-----------------------+------+------------+-----------+
We can execute commands in the container using lxc exec
:
lxc exec stirring-beagle -- ls -la
which will run the provided command as root on the target container:
total 7
drwx------ 3 root root 5 Jun 29 11:29 .
drwxr-xr-x 22 root root 22 Jun 19 23:52 ..
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 3 Jun 29 11:29 .ssh
Shell access to the container can be obtained with lxc exec stirring-beagle /bin/bash
Note that since we also set up networking, the container has an IPv4 address (as shown by lxc list
) and can be also reached via ssh from the host. This, however, requires importing an ssh key in the container first.
Once the container is no longer needed, it can be stopped
lxc stop stirring-beagle
and destroyed
lxc delete stirring-beagle