Creating LXC/LXD Images
Launch a server such as Ubuntu 16.04.
Get the local ip address of server
lxcmachine@lxcuser:~$ ifconfig eth0 Link encap:Ethernet HWaddr 0a:74:c8:bb:b3:2c inet addr:172.31.32.48 Bcast:172.31.47.255 Mask:255.255.240.0 inet6 addr: fe80::874:c8ff:febb:b32c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1 RX packets:6621 errors:0 dropped:0 overruns:0 frame:0 TX packets:1465 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8209848 (8.2 MB) TX bytes:769272 (769.2 KB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:192 errors:0 dropped:0 overruns:0 frame:0 TX packets:192 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:15864 (15.8 KB) TX bytes:15864 (15.8 KB)
Set the https port to listen to
lxcmachine@lxcuser:~$ lxc config set core.https_address "[::]:8443"
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
Set the password for the lxc remote host
lxcmachine@lxcuser:~$ lxc config set core.trust_password yourpassword
Login to local lxc server and add remote lxc server
lxcmachine@lxcuser:~$ lxc remote add remotelxc 172.31.32.48
Certificate fingerprint: a50785a6bae49089567b111d1d443f258662cc1fcf3fcd7a2085afb8c6391893ok (y/n)? y
Admin password for remotelxc:
Client certificate stored at server: remotelxc
List remote lxc server
lxcmachine@lxcuser:~$ lxc list remotelxc:
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
Publish container image
lxcmachine@lxcuser:~$ lxc publish web/initialconfig --alias nginx-example
Container published with fingerprint: c6bd5aaeaff448349f58f6afe6cfe2735ead6e466a8bee9ac70b6ad0498338db
Launch container on remote
lxcmachine@lxcuser:~$ lxc launch nginx-example remotelxc:new-nginx-server
Creating new-nginx-server
Starting new-nginx-server
lxcmachine@lxcuser:~$ lxc list remotelxc:
+------------------+---------+------+------+------------+-----------+| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------------------+---------+------+------+------------+-----------+| new-nginx-server | RUNNING | 10.191.207.251 (eth0) | d85:4265:5a21:1307:216:3eff:fe13:3c4e (eth0)| PERSISTENT | 0 |
+------------------+---------+------+------+------------+-----------+
Export container image
lxcmachine@lxcuser:~$ mkdir export-nginx
lxcmachine@lxcuser:~$ lxc image export nginx-example export-nginx/
Image exported successfully!
lxcmachine@lxcuser:~$ ls export-nginx/
c6bd5aaeaff448349f58f6afe6cfe2735ead6e466a8bee9ac70b6ad0498338db.tar.gz