docker及容器设置开机自动启动

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

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或容器名
posted @ 2020-06-19 10:04  豌里个豆  阅读(1669)  评论(0编辑  收藏  举报