dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
阅读:1220回复:1

docker run --restart 容器自启动

楼主#
更多 发布于:2016-07-29 10:05
举个栗子:docker 宿主机重启,容器自动启动;
docker run -d --restart="always" --publish="8500:8500" --hostname="consul" --name="consul" consul

功能

默认情况下,docker 宿主机重启后,容器是stop 状态的,通过在创建容器时添加 --restart 参数,则容器可以自启动,建议生产环境的容器 添加--restart 参数,非常方便

帮助
docker run --help | grep "restart"
 --restart=no                    Restart policy to apply when a container exits

#
dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
沙发#
发布于:2018-08-21 10:04
docker 容器 restart 策略
示例
docker run --name $(hostname) --restart=unless-stopped -p 6000:6000 -tid mysite:0.0.3

参数
--restart

no
Do not automatically restart the container when it exits. This is the default.

on-failure[:max-retries]
Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.

always
Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.

unless-stopped

Always restart the container regardless of the exit status, but do not start it on daemon startup if the container has been put to a stopped state before.

https://docs.docker.com/engine/reference/run/#restart-policies-restart
#
游客

返回顶部