如何在Linux启动时自动启动LXD容器

系统 Linux
当 LXD 在启动时运行,你就可以随时启动容器。你需要将 boot.autostart 设置为 true。你可以使用 boot.autostart.priority(默认值为 0)选项来定义启动容器的顺序(从最高开始)。你也可以使用 boot.autostart.delay(默认值 0)选项定义在启动一个容器后等待几秒后启动另一个容器。

 

 

[[214506]]

Q:我正在使用基于 LXD(“Linux 容器”)的虚拟机。如何在 Linux 系统中启动时自动启动 LXD 容器?

当 LXD 在启动时运行,你就可以随时启动容器。你需要将 boot.autostart 设置为 true。你可以使用 boot.autostart.priority(默认值为 0)选项来定义启动容器的顺序(从***开始)。你也可以使用 boot.autostart.delay(默认值 0)选项定义在启动一个容器后等待几秒后启动另一个容器。

 

语法

上面讨论的关键字可以使用 lxc 工具用下面的语法来设置:

  1. $ lxc config set {vm-name} {key} {value}
  2. $ lxc config set {vm-name} boot.autostart {true|false}
  3. $ lxc config set {vm-name} boot.autostart.priority integer
  4. $ lxc config set {vm-name} boot.autostart.delay integer

 

如何在 Ubuntu Linux 16.10 中让 LXD 容器在启动时启动?

输入以下命令:

  1. $ lxc config set {vm-name} boot.autostart true

设置一个 LXD 容器名称 “nginx-vm” 以在启动时启动

  1. $ lxc config set nginx-vm boot.autostart true

你可以使用以下语法验证设置:

  1. $ lxc config get {vm-name} boot.autostart
  2. $ lxc config get nginx-vm boot.autostart

示例输出:

  1. true

你可以使用下面的语法在启动容器后等待 10 秒钟后启动另一个容器:

  1. $ lxc config set nginx-vm boot.autostart.delay 10

***,通过设置***值来定义启动容器的顺序。确保 dbvm 容器首先启动,然后再启动 nginxvm。

  1. $ lxc config set db_vm boot.autostart.priority 100
  2. $ lxc config set nginx_vm boot.autostart.priority 99

使用下面的 bash 循环在 Linux 上查看所有配置值:

  1. #!/bin/bash
  2. echo 'The current values of each vm boot parameters:'
  3. for c in db_vm nginx_vm memcache_vm
  4. do
  5. echo "*** VM: $c ***"
  6. for v in boot.autostart boot.autostart.priority boot.autostart.delay
  7. do
  8. echo "Key: $v => $(lxc config get $c $v) "
  9. done
  10. echo ""
  11. done

示例输出:

Fig.01: Get autostarting LXD containers values using a bash shell script

Fig.01: Get autostarting LXD containers values using a bash shell script 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2017-03-10 10:37:16

Linux命令脚本

2010-05-25 18:57:42

启动postfix

2020-06-04 17:00:37

Linux命令脚本

2014-01-06 11:24:51

Linux桌面启动程序

2022-02-17 08:20:17

Spring执行代码SpringBoot

2018-11-23 15:25:00

Windows10Windows启动时间

2009-06-17 17:06:20

2020-10-26 10:11:45

Jupyter Not早起Python开发

2021-08-26 13:55:45

systemdLinux目标

2020-02-12 08:50:05

Linux命令启动时间

2021-08-26 11:09:51

systemdLinux

2010-05-06 18:42:15

Unix系统

2019-04-22 12:25:40

UbuntuLinux IP地址

2018-08-22 10:55:53

WindowsWindows 10系统故障

2021-11-04 12:42:55

RocketMQ启动消费

2019-03-25 10:30:11

Windows 10 Windows程序

2018-10-19 10:45:13

WindowsWindows10应用程序

2022-05-04 17:50:51

Linux

2018-05-21 08:52:15

Linux应用程序启动时间

2009-03-13 19:24:58

Windows7Bug启动
点赞
收藏

51CTO技术栈公众号