前言
部署项目服务器时,为了应对停电等情况影响正常web项目的访问,会把Docker容器设置为开机自动启动。 在使用docker run启动容器时,使用--restart参数来设置,具体参数如下详解
no: 容器退出时,不重启容器,默认选项
on-failure:只有在非0状态退出时才从新启动容器;
always:无论退出状态是如何,都重启容器;
示例
# 指定重启次数
docker run --restart=on-failure:10 redis
# 不管是否报错都一直重启,直到启动未知
docker run --restart=always redis