vlambda博客
学习文章列表

docker重启 开启或关闭自启容器

代码来源:博客园

原文链接:https://www.cnblogs.com/jtlgb/p/12220815.html

本文版权归原作者所有,如有侵权请立即与我联系,我将及时处理。

创建容器时添加参数  --restart=always 后,当 docker 重启时,容器自动启动。

使用方法:

docker container update --restart=always <CONTAINER ID>

操作实例如下:

[root@localhost mnt]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES46cdfc60b7a6 nginx "nginx -g 'daemon ..." About a minute ago Up 42 seconds 80/tcp n379d55a734c26 nginx "nginx -g 'daemon ..." About a minute ago Up 42 seconds 80/tcp n2f7b2206c019d nginx "nginx -g 'daemon ..." About a minute ago Up 46 seconds 80/tcp n1[root@localhost mnt]# docker container update --restart=always n1n1[root@localhost mnt]# systemctl restart docker[root@localhost mnt]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES46cdfc60b7a6 nginx "nginx -g 'daemon ..." 2 minutes ago Exited (0) 5 seconds ago n379d55a734c26 nginx "nginx -g 'daemon ..." 2 minutes ago Exited (0) 5 seconds ago n2f7b2206c019d nginx "nginx -g 'daemon ..." 2 minutes ago Up 2 seconds 80/tcp n1

如果你想取消掉
命令如下:

docker update --restart=no <CONTAINER ID>