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

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

主站蜘蛛池模板: 丽江市| 甘德县| 西城区| 阿鲁科尔沁旗| 萍乡市| 建平县| 池州市| 东阳市| 南投市| 确山县| 浦城县| 兰州市| 定边县| 石景山区| 永定县| 淄博市| 浮山县| 黎川县| 连江县| 确山县| 阳江市| 和顺县| 昌黎县| 沧州市| 平江县| 永宁县| 宜宾市| 八宿县| 格尔木市| 瓮安县| 惠水县| 镇安县| 和林格尔县| 林州市| 怀宁县| 金阳县| 万全县| 日照市| 高唐县| 安宁市| 昌乐县|