In this recipe, we will learn about some advanced options provided by LXD.
Follow these steps to deal with LXD containers:
copy
command to create such clones:$ lxc copy c1 c2 # lxc copy source destination
You can also create a temporary copy with the --ephemeral
flag and it will be deleted after one use.
lxc publish
command allows you to export existing containers as a new image. The resulting image will contain all modifications from the original container:$ lxc publish c1 --alias nginx # after installing nginx
The container to be published should be in the stopped state. Alternatively, you can use the --force
flag to publish a running container, which will internally stop the container before exporting.
move
command helps you with moving containers across hosts. If you move a container on the same host, the original container will be renamed. Note that the container to be renamed must not be running:$ lxc move c1 c2 # container c1 will be renamed to c2
$ lxc snapshot c1 snap1 # lxc snapshot container cnapshot
lxc list
command will show you the number of snapshots for a given container. To get the details of every snapshot, check the container information with the lxc info
command:$ lxc info c1 ... Snapshots: c1/shap1 (taken at 2016/05/22 10:34 UTC) (stateless)
lxc restore
, as follows:$ lxc restore c1 snap1 # lxc restore container snapshot
lxc copy
, as follows:$ lxc copy c1/snap1 c4 # lxc copy container/snapshot new_container
lxc delete
, as follows:$ lxc delete c1/snap1 # lxc delete container/snapshot
Most of these commands work with the rootfs
or root
filesystem of containers
. The rootfs
is stored under the /var/lib/lxd/containers
directory. Copying creates a copy of the rootfs
while deleting removes the rootfs
for a given container. These commands benefit with the use of the ZFS file system. Features such as copy-on-write speed up the copy and snapshot operations while reducing the total disk space use.