Docker restart命令重启一个或多个容器。帮助如下:
[root@localhost ~]# docker restart --help Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] Restart one or more containers Options: -t, --time int Seconds to wait for stop before killing the container (default 10)
其中:
-t, --time 在杀死容器之前等待stop的秒数(默认为10)
实例:根据容器ID重启容器。如下:
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ddfd18831621 centos "/bin/bash" 4 minutes ago Exited (137) 4 minutes ago gifted_lovelace [root@localhost ~]# docker restart ddfd18831621 ddfd18831621
我们也可以一次重启多个容器。如下:
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ddfd18831621 centos "/bin/bash" 6 minutes ago Exited (137) 8 seconds ago gifted_lovelace c100b8e45fe8 ubuntu "/bin/bash" 6 minutes ago Exited (0) 5 minutes ago goofy_jepsen [root@localhost ~]# docker restart ddfd18831621 c100b8e45fe8 ddfd18831621 c100b8e45fe8
也可以根据容器NAMES重启容器。如下:
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ddfd18831621 centos "/bin/bash" 7 minutes ago Exited (137) 11 seconds ago gifted_lovelace [root@localhost ~]# docker restart gifted_lovelace gifted_lovelace