...
Code Block | ||
---|---|---|
| ||
lxc list
+-------------+---------+----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-------------+---------+----------------------+------+------------+-----------+
| container01 | RUNNING | 10.94.217.171 (eth0) | | PERSISTENT | 0 |
+-------------+---------+----------------------+------+------------+-----------+
# Inspect the container,
lxc info container01
Name: container01
Remote: unix:/var/lib/lxd/unix.socket
Architecture: x86_64
Created: 2016/12/22 03:37 UTC
Status: Running
Type: persistent
Profiles: default
Pid: 19681
Ips:
eth0: inet 10.94.217.171 vethDXUYOE
eth0: inet6 fe80::216:3eff:fe07:69ea vethDXUYOE
lo: inet 127.0.0.1
lo: inet6 ::1
Resources:
Processes: 26
Disk usage:
root: 144.32MB
Memory usage:
Memory (current): 23.24MB
Memory (peak): 45.28MB
# ... |
For illustration of flexiblity and preparing for the next section, we will update and setup Apache inside of container01.
...
The most compelling reason to use LXD is ability to transport between containers. Setup a second LXD host on the same network. In this example we end up with two hosts,
Host | Containers | Comment |
---|---|---|
myhost01 | Where we setup container01 with Apache running inside. | This will be the host we can to copy the container from also called remote host. |
myhost02 | Just empty at the moment. | This will be the client also called the local machine. |
Expose Remote Host
In order for the local machine to connect, the remote host needs to be setup to be exposed on the network with a password. Following the instructions here, that work has been done while initializing LXD.
...
Code Block | ||
---|---|---|
| ||
lxc remote add myhost02myhost01 192.168.0.110109 Certificate fingerprint: 119846805c57c71ce8308c6623977202f990eff85d334ddcfef6cacca4cfd8837344c171bdc30a20e215e536a7959353b55ab6243a019819fb62385fa02d26b2 ok (y/n)? y Admin password for myhost02myhost01: Client certificate stored at server: myhost02myhost01 |
Now the list has been updated to have myhost02 as an entry,
Code Block | ||
---|---|---|
| ||
lxc remote list +-----------------+------------------------------------------+---------------+--------+--------+ | NAME | URL | PROTOCOL | PUBLIC | STATIC | +-----------------+------------------------------------------+---------------+--------+--------+ | images | https://images.linuxcontainers.org | simplestreams | YES | NO | +-----------------+------------------------------------------+---------------+--------+--------+ | local (default) | unix:// | lxd | NO | YES | +-----------------+------------------------------------------+---------------+--------+--------+ | myhost02myhost01 | https://192.168.0.110109:8443 | lxd | NO | NO | +-----------------+------------------------------------------+---------------+--------+--------+ | ubuntu | https://cloud-images.ubuntu.com/releases | simplestreams | YES | YES | +-----------------+------------------------------------------+---------------+--------+--------+ | ubuntu-daily | https://cloud-images.ubuntu.com/daily | simplestreams | YES | YES | +-----------------+------------------------------------------+---------------+--------+--------+ |
...
Interaction is exactly the same as a local container except you specify the registered lxd host name,
Code Block | ||
---|---|---|
| ||
lxc list myhost02myhost01: # INotice knowmyhost01 thehas coloncontainer01 iswhich optionalwe buthad it gets you thinking about the actual container on the host. setup. +-------------+---------+----------------------+------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+----------------------+------+------------+-----------+ | NAMEcontainer01 | STATERUNNING | IPV4 10.94.217.171 (eth0) | IPV6 | TYPEPERSISTENT | SNAPSHOTS 0 | +-------------+---------+----------------------+------+------------+-----------+ lxc info myhost01:container01 lxc info myhost01:container01 Name: container01 Remote: https://192.168.0.109:8443 Architecture: x86_64 Created: 2016/12/22 03:37 UTC Status: Running Type: persistent Profiles: default Pid: 22659 Ips: eth0: inet 10.94.217.171 vethCIJK85 eth0: inet6 fe80::216:3eff:fe07:69ea vethCIJK85 lo: inet 127.0.0.1 lo: inet6 ::1 Resources: Processes: 81 Disk usage: root: 147.63MB Memory usage: Memory (current): 20.07MB Memory (peak): 42.18MB # .... # While local machine has someno containers. lxc list list +------+-------+------+------+------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+-------+------+------+------+-----------+ |
Also keep this concept in mind even when referencing cached images.
Cloning Containers Between Hosts
We can now clone from myhost01, container01 (which is running Apache into) into myhost02.
There are two key methods. Clone semi-live using snapshots and shutting down first.
Shutdown Approach
Log into myhost02
Code Block | ||
---|---|---|
| ||
lxc stop myhost01:container01 # Verify container stopped lxc list myhost01: +-------------+---------+------+------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE IPV4 | SNAPSHOTS | +-------------+---------+------+------+------------+-----------+ | container01 | IPV6STOPPED | TYPE | | SNAPSHOTSPERSISTENT | 0 | +-------------+---------+------+------+------------+-----------+ lxc copy myhost01:container01 web01 |
A copy of container01 has been copied to myhost02 and given the container name web01. Everything is the same except for (...),
Code Block | ||
---|---|---|
| ||
lxc list +-------+---------+------+------+------------+-----------+ | container01NAME | RUNNING | 10.94.217.171 (eth0) STATE | IPV4 | PERSISTENTIPV6 | 0 TYPE | SNAPSHOTS | +-------+---------+------+------+------------+-----------+ | web01 | STOPPED | | | PERSISTENT | 0 | +-------+---------+------+------+------------+-----------+ |
...
Semi-Live Approach
...
Advanced Tuning of Containers
...