官术网_书友最值得收藏!

  • Linux:Powerful Server Administration
  • Uday R. Sawant Oliver Pelz Jonathan Hobson William Leemans
  • 458字
  • 2021-07-09 18:17:01

Managing LXD containers

We have installed LXD and deployed our first container with it. In this recipe, we will learn various LXD commands that manage the container lifecycle.

Getting ready…

Make sure that you have followed the previous recipes and created your first container.

How to do it…

Follow these steps to manage LXD containers:

  1. Before we start with container management, we will need a running container. If you have been following the previous recipes, you should already have a brand new container running on your system. If your container is not already running, you can start it with the lxc start command:
    $ lxc start c1
    
  2. To check the current state of a container, use lxc list, as follows:
    $ lxc list c1
    

    This command should list only containers that have c1 in their name.

  3. You can also set the container to start automatically. Set the boot.autostart configuration option to true and your container will start automatically on system boot. Additionally, you can specify a delay before autostart and a priority in the autostart list:
    $ lxc config set c1 boot.autostart true
    
  4. Once your container is running, you can open a bash session inside a container using the lxc exec command:
    $ lxc exec c1 -- bash
    root@c1:~# hostname
    c1
    

    This should give you a root shell inside a container. Note that to use bash, your container image should have a bash shell installed in it. With alpine containers, you need to use sh as the shell as alpine does not contain the bash shell.

  5. LXD provides the option to pause a container when it's not being actively used. A paused container will still hold memory and other resources assigned to it, but not receive any CPU cycles:
    $ lxc pause c1
    
  6. Containers that are paused can be started again with lxc start.
  7. You can also restart a container with the lxc restart command, with the option to perform a stateful or stateless restart:
    $ lxc restart --stateless c1
    
  8. Once you are done working with the container, you can stop it with the lxc stop command. This will release all resources attached to that container:
    $ lxc stop c1
    

    At this point, if your container is an ephemeral container, it will be deleted automatically.

  9. If the container is no longer required, you can explicitly delete it with the lxc delete command:
    $ lxc delete c1
    

There's more…

For those who do not like to work with command line tools, you can use a web-based management console known as LXD GUI. This package is still in beta but can be used on your local LXD deployments. It is available on GitHub at https://github.com/dobin/lxd-webgui.

See also

主站蜘蛛池模板: 申扎县| 五原县| 陇川县| 疏勒县| 罗江县| 独山县| 巴马| 永昌县| 甘孜县| 兴山县| 余姚市| 洱源县| 青冈县| 福鼎市| 新竹市| 富裕县| 噶尔县| 南康市| 平乐县| 巴彦县| 霍邱县| 新乡县| 石家庄市| 南宫市| 烟台市| 咸宁市| 伊金霍洛旗| 正安县| 宁远县| 洛浦县| 平远县| 绥化市| 广宁县| 深泽县| 淮安市| 昭觉县| 马关县| 银川市| 都安| 疏勒县| 孝昌县|