环境:CentOS 7.6 参考docker容器怎么设置开机启动

此方法适用于yum安装的各种服务

查看已启动的服务

systemctl list-units --type=service

已设置了开机自动启动的服务

systemctl list-unit-files | grep enable

设置开机启动

systemctl enable docker.service

移除开机启动

systemctl disable docker.service

docker容器设置开机自动启动

新容器

启动时添加--restart=always参数

--restart的参数有
Flag	        Description
no		不自动重启容器. (默认value)
on-failure 	容器发生error而退出(容器退出状态不为0)重启容器
unless-stopped 	在容器已经stop掉或Docker stoped/restarted的时候才重启容器
always 	        在容器已经stop掉或Docker stoped/restarted的时候才重启容器

已启动的容器

docker update --restart=always 容器id或容器名

相关文章:

  • 2021-06-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2023-02-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
相关资源
相似解决方案