Ubuntu下docker及portainer自动启动

webpenson, 15 八月, 2021

docker设置自动启动

一、docker服务设置自动启动

查看已启动的服务
systemctl list-units --type=service

查看是否设置开机启动
systemctl list-unit-files | grep enable

设置开机启动
systemctl enable docker.service

关闭开机启动
systemctl disable docker.service

二、docker容器设置自动启动

启动时加--restart=always

docker run -d --name portainerUI -p 8000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer

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

如果已经过运行的项目
如果已经启动的项目,则使用update更新:
docker update --restart=always portainerUI

评论