删除终止状态的容器
首先找到一个终止 状态的容器
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9cd3a0312b95 docker.io/ubuntu:latest "/bin/sh -c 'while tr" 11 minutes ago Exited (0) 5 minutes ago elated_lalande
删除
[root@docker ~]# docker rm 9cd3a0312b95
9cd3a0312b95
测试:查看
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2424fa7a5346 docker.io/ubuntu:latest "/bin/sh -c top" 14 minutes ago Exited (1) 14 minutes ago dreamy_ritchie
8c8420123536 docker.io/ubuntu:latest "/bin/sh" 15 minutes ago Exited (0) 15 minutes ago modest_banach
11c1437847cb docker.io/ubuntu:latest "/bin/bash" 35 minutes ago Exited (0) 32 minutes ago mad_fermi
5bd73ca9dcdb docker.io/ubuntu:latest "/bin/bash" 42 minutes ago Up 20 minutes sad_brahmagupta
6378eb77bbdf docker.io/ubuntu:latest "/bin/bash" 3 hours ago Exited (0) 3 hours ago berserk_bhaskara
940e7ebbb19d docker.io/ubuntu:latest "/bin/bash" 3 hours ago Exited (127) 3 hours ago desperate_mayer
5dbb944ba21f docker.io/ubuntu "/bin/bash" 4 hours ago Exited (0) 4 hours ago hopeful_mahavira
[root@docker ~]#
可以发现已经没有了。
删除运行中的容器
首先找到一个运行中的容器,从上面的测试输出可以发现 id是 5bd73ca9dcdb 的是运行状态的。
删除:
[root@docker ~]# docker rm -f 5bd73ca9dcdb
5bd73ca9dcdb
[root@docker ~]#
测试:查看
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2424fa7a5346 docker.io/ubuntu:latest "/bin/sh -c top" 18 minutes ago Exited (1) 18 minutes ago dreamy_ritchie
8c8420123536 docker.io/ubuntu:latest "/bin/sh" 19 minutes ago Exited (0) 19 minutes ago modest_banach
11c1437847cb docker.io/ubuntu:latest "/bin/bash" 38 minutes ago Exited (0) 36 minutes ago mad_fermi
6378eb77bbdf docker.io/ubuntu:latest "/bin/bash" 3 hours ago Exited (0) 3 hours ago berserk_bhaskara
940e7ebbb19d docker.io/ubuntu:latest "/bin/bash" 3 hours ago Exited (127) 3 hours ago desperate_mayer
5dbb944ba21f docker.io/ubuntu "/bin/bash" 4 hours ago Exited (0) 4 hours ago hopeful_mahavira
[root@docker ~]#
可以发现已经没有了