Docker kill命令强制停止一个或多个容器。帮助信息如下:
[root@localhost ~]# docker kill --help Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] Kill one or more running containers Options: -s, --signal string Signal to send to the container (default "KILL")
其中:
-s, --signal string 发送信号到容器(默认“KILL”)
实例:根据容器ID强制停止容器。如下:
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ddfd18831621 centos "/bin/bash" 10 minutes ago Up 2 minutes gifted_lovelace [root@localhost ~]# docker kill ddfd18831621 ddfd18831621
一次性强制停止多个容器。如下:
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ece33456afe1 centos "/bin/bash" 8 seconds ago Up 7 seconds sharp_hopper 574ad33d0772 ubuntu "/bin/bash" 11 seconds ago Up 9 seconds blissful_jang [root@localhost ~]# docker kill ece33456afe1 574ad33d0772 ece33456afe1 574ad33d0772
根据 NAMES 强制停止容器。如下:
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES af9ba2baa42e centos "/bin/bash" 5 seconds ago Up 4 seconds musing_cerf [root@localhost ~]# docker kill musing_cerf musing_cerf
同时使用容器ID和NAMES强制停止多个容器。如下:
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5a97a6b111af memcached:1.4.21 "memcached" 42 seconds ago Up 40 seconds 11211/tcp quirky_bhabha 5c27f0d18a73 centos "/bin/bash" About a minute ago Up About a minute festive_keldysh b60d1784c305 ubuntu "/bin/bash" 2 minutes ago Up 2 minutes naughty_wozniak [root@localhost ~]# docker kill 5a97a6b111af festive_keldysh naughty_wozniak 5a97a6b111af festive_keldysh naughty_wozniak