環境: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或容器名