Managing LXD container/snapshots

Hi I created 2 LXD containers for Ubuntu 18.04 and CentOS 7.5 and have some questions regarding managing snapshots and containers.

Questions

  1. how to delete snapshots (not containers) ? i.e. delete csnapshot0 created below ?

  2. how to re-create a container with a specific internal IP address if possible ? so if i deleted below container centos75, how would i go about recreating that container named centos75 with the same internal IP as previously used 10.71.164.168 ?

  3. how to list snapshots ?

  4. any way to dig detail into the details of what a snapshot contains ?

I created them

lxc launch ubuntu:18.04 ubuntu18
lxc launch images:centos/7 centos75
lxc list
+----------+---------+----------------------+-----------------------------------------------+------------+-----------+
|   NAME   |  STATE  |         IPV4         |                     IPV6                      |    TYPE    | SNAPSHOTS |
+----------+---------+----------------------+-----------------------------------------------+------------+-----------+
| centos75 | RUNNING | 10.71.164.168 (eth0) | fd42:769c:ebd9:a0f7:216:3eff:fefd:23a2 (eth0) | PERSISTENT | 1         |
+----------+---------+----------------------+-----------------------------------------------+------------+-----------+
| ubuntu18 | RUNNING | 10.71.164.145 (eth0) | fd42:769c:ebd9:a0f7:216:3eff:fe42:4ca8 (eth0) | PERSISTENT | 2         |
+----------+---------+----------------------+-----------------------------------------------+------------+-----------+

made snapshots

lxc snapshot ubuntu18 usnap0
lxc snapshot centos75 csnap0
lxc list ubuntu18 -c4 | egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" 
10.71.164.145

lxc list centos75 -c4 | egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
10.71.164.168
1 Like
  1. To list the snapshots of container ubuntu18, run

    lxc info ubuntu18
    
  2. To delete a snapshot, run

    lxc delete ubuntu18/usnap0
    

    That’s the syntax to specify the snapshot usnap0 of the container ubuntu18.

Each container that you create, gets a random MAC address. That MAC address though stays permanent for the lifetime of the container.
The dnsmasq DHCP server of LXD will assign an IP address to each of those MAC addresses. Therefore, each container will practically keep the same IP address.
To get a container to receive a specific IP address, there are several options. You can set a static IP address (using the appropriate lxc command).

I think it’s not easy to get the difference between a snapshot and the base image.

2 Likes

thanks so something like https://www.cyberciti.biz/faq/linux-containers-assign-static-ip-address-using-dnsmasq/ ?

For static leases, see https://stgraber.org/2016/10/27/network-management-with-lxd-2-3/
The command looks like

lxc config device set ubuntu18 eth0 ipv4.address 10.10.10.50

You can also work with the MAC addresses as shown in the post at cyberciti.biz.

1 Like

Thanks @simos perfect :slight_smile:

Type lxc list --help to get the list of available difference outputs.
Most notably, you can switch to having CSV output which is friendlier to shell scripts.
Also, you can output to the JSON format that can be accessed with the jq command.

Note that when you lxc list mycontainername, lxc is using mycontainername as a filter.
Therefore, if you have two containers named mycontainername1 and mycontainername2, they will both show up in the output!
To force to show the exact name, try with lxc list ^mycontainername$. Those ^ and $ are special shell characters.

1 Like

thanks for those tips very useful indeed !

I just migrated using lxd.migrate from apt version of lxd 3.0.0 to snap lxd 3.1 and was wondering is there any effect on previous container made snapshots in terms of snapshot restores ? or do previous lxd version/repo apt vs snap made snaphots restore fine regardless ?

Should all be fine, lxd.migrate moves all your data over to the snap based storage and all LXD artifacts have always been backward compatible so restoring a snapshot made with LXD 2.0 on a LXD 3.1 server will work fine.

2 Likes

Thanks @stgraber