- Linux:Powerful Server Administration
- Uday R. Sawant Oliver Pelz Jonathan Hobson William Leemans
- 546字
- 2021-07-09 18:17:02
Managing LXD containers – advanced options
In this recipe, we will learn about some advanced options provided by LXD.
How to do it…
Follow these steps to deal with LXD containers:
- Sometimes, you may need to clone a container and have it running as a separate system. LXD provides a
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. - Similarly, you can create a container, configure it as per you requirements, have it stored as an image, and use it to create more containers. The
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. - You can also move the entire container from one system to another. The
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
- Finally, we have the snapshot and restore functionality. You can create snapshots of the container or, in simple terms, take a backup of its current state. The snapshot can be a stateful snapshot that stores the container's memory state. Use the following command to create a snapshot of your container:
$ lxc snapshot c1 snap1 # lxc snapshot container cnapshot
- The
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 thelxc info
command:$ lxc info c1 ... Snapshots: c1/shap1 (taken at 2016/05/22 10:34 UTC) (stateless)
Tip
You can skip the snapshot name and LXD will name it for you. But, as of writing this, there's no option to add a description with snapshots. You can use the filename to describe the purpose of each snapshot.
- Once you have the snapshots created, you can restore it to go back to a point or create new containers out of your snapshots and have both states maintained. To restore your snapshot, use
lxc restore
, as follows:$ lxc restore c1 snap1 # lxc restore container snapshot
- To create a new container out of your snapshot, use
lxc copy
, as follows:$ lxc copy c1/snap1 c4 # lxc copy container/snapshot new_container
- When you no longer need a snapshot, delete it with
lxc delete
, as follows:$ lxc delete c1/snap1 # lxc delete container/snapshot
How it works…
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.
- Circos Data Visualization How-to
- 蕩胸生層云:C語言開發(fā)修行實(shí)錄
- WOW!Illustrator CS6完全自學(xué)寶典
- 計(jì)算機(jī)控制技術(shù)
- 計(jì)算機(jī)網(wǎng)絡(luò)技術(shù)實(shí)訓(xùn)
- 大數(shù)據(jù)處理平臺(tái)
- 完全掌握AutoCAD 2008中文版:綜合篇
- Learn CloudFormation
- 云原生架構(gòu)進(jìn)階實(shí)戰(zhàn)
- 分?jǐn)?shù)階系統(tǒng)分析與控制研究
- Hands-On Data Warehousing with Azure Data Factory
- 從零開始學(xué)Java Web開發(fā)
- Mastering Geospatial Analysis with Python
- 網(wǎng)絡(luò)脆弱性掃描產(chǎn)品原理及應(yīng)用
- Web璀璨:Silverlight應(yīng)用技術(shù)完全指南