报错如下:
[root@ temp]# docker rmi jc_tomcat-8.0.1
Error response from daemon: conflict: unable to remove repository reference "jc_tomcat-8.0.1" (must force) - container 84a299749313 is using its referenced image f55e749e8a07
翻译:容器506ec627bcc9正在使用它所引用的镜像f55e749e8a07
查看运行中的容器:
[root@ temp]# docker ps;
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
发现没有任何的运行中容器
显示所有的容器,包括未运行的:docker ps -a
[root@izf8z14idfp0rxiag38b06z temp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4ae739521f00 jc_tomcat-8.0.1 "/bin/sh -c '/usr/..." 6 minutes ago Exited (1) 6 minutes ago flamboyant_panini
84a299749313 jc_tomcat-8.0.1 "/bin/sh -c '/usr/..." 6 minutes ago Exited (1) 6 minutes ago naughty_lumiere
506ec627bcc9 f55e749e8a07 "/bin/sh -c '/usr/..." 7 minutes ago Exited (1) 7 minutes ago musing_fermi
67ea79626502 jc_jdk1.8.0_121 "/bin/sh -c 'java ..." 15 minutes ago Exited (0) 15 minutes ago unruffled_lamarr
3b45cee7f2da jc_jdk1.8.0_121 "/bin/sh -c 'java ..." 12 hours ago Exited (0) 12 hours ago silly_spence
b1f9388f6053 jc_jdk1.8.0_281 "/bin/sh -c java-v..." 12 hours ago Exited (127) 12 hours ago hungry_keller
365d420f3cea 281cf0a9cc41 "/bin/sh -c /bin/bash" 6 weeks ago Exited (0) 4 weeks ago optimistic_knuth
28100648ce35 281cf0a9cc41 "/bin/sh -c /bin/bash" 6 weeks ago Exited (0) 6 weeks ago gifted_bhabha
2b163f98e782 fe89033e0d5f "docker-entrypoint..." 6 weeks ago Exited (0) 6 weeks ago sharp_lovelace
c3870b0823eb fe89033e0d5f "docker-entrypoint..." 6 weeks ago Exited (0) 6 weeks ago practical_liskov
6e68b95de66f fe89033e0d5f "docker-entrypoint..." 6 weeks ago Exited (0) 6 weeks ago eager_ritchie
ebaee97d2ee1 fc68cd9d515c "/bin/sh -c 'yum -..." 6 weeks ago Exited (127) 6 weeks ago elegant_williams
2d7b08f6faa4 ef47f3b6dc11 "docker-entrypoint..." 6 weeks ago Exited (0) 6 weeks ago modest_galileo
f9644743a08c ef47f3b6dc11 "docker-entrypoint..." 6 weeks ago Exited (0) 6 weeks ago inspiring_bhaskara
d0c7d0609e21 ef47f3b6dc11 "docker-entrypoint..." 6 weeks ago Created cocky_kilby
32a7db567c45 ef47f3b6dc11 "docker-entrypoint..." 6 weeks ago Created clever_beaver
9ec1c524d156 ef47f3b6dc11 "docker-entrypoint..." 6 weeks ago Exited (0) 6 weeks ago angry_kilby
492c54ba41d6 tomcat "catalina.sh run" 2 months ago Created friendly_hypatia
6f3d7e5c0462 feba8d001e3f "catalina.sh run" 2 months ago Exited (255) 6 weeks ago 0.0.0.0:8080->8080/tcp musing_ramanujan
1193fe41895b feba8d001e3f "catalina.sh run" 2 months ago Exited (143) 2 months ago nifty_kowalevski
0e3e69827051 ef47f3b6dc11 "docker-entrypoint..." 2 months ago Exited (0) 2 months ago ecstatic_jang
3c6edc1d6d41 zookeeper "/docker-entrypoin..." 3 months ago Exited (137) 3 months ago suspicious_nobel
8d264892c1f3 centos "/bin/bash" 3 months ago Exited (0) 3 months ago jolly_lalande
f9240878bb8f centos "/bin/bash" 3 months ago Exited (0) 3 months ago angry_banach
7a04396d7c80 3edbbd4366dd "/bin/sh -c /bin/bash" 3 months ago Exited (0) 3 months ago festive_colden
438d8eba3c8a 3edbbd4366dd "/bin/sh -c /bin/bash" 3 months ago Exited (0) 3 months ago affectionate_darwin
dd3ecd87872b nginx "/docker-entrypoin..." 3 months ago Exited (0) 3 months ago admiring_engelbart
aaa0d4ca226b nginx "/docker-entrypoin..." 3 months ago Exited (0) 3 months ago keen_payne
ac85f3f63d55 nginx "/docker-entrypoin..." 3 months ago Exited (0) 3 months ago tender_wilson
99150117b2dc nginx "/docker-entrypoin..." 3 months ago Exited (0) 3 months ago adoring_ptolemy
卧槽!!这么多
删除对应的容器通过命令:docker rm 容器id 或 容器名称
或者
删除所有已停止的容器:docker rm $(docker ps -aq)
例如:
一条命令实现停用并删除容器:docker stop $(docker ps -q) & docker rm -f $(docker ps -aq)
[root@izf8z14idfp0rxiag38b06z temp]# docker stop $(docker ps -q) & docker rm -f $(docker ps -aq)
[1] 32559
"docker stop" requires at least 1 argument(s).
See 'docker stop --help'.
Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
Stop one or more running containers
4ae739521f00
84a299749313
506ec627bcc9
67ea79626502
3b45cee7f2da
b1f9388f6053
365d420f3cea
28100648ce35
2b163f98e782
c3870b0823eb
6e68b95de66f
ebaee97d2ee1
2d7b08f6faa4
f9644743a08c
d0c7d0609e21
32a7db567c45
9ec1c524d156
492c54ba41d6
6f3d7e5c0462
1193fe41895b
0e3e69827051
3c6edc1d6d41
8d264892c1f3
f9240878bb8f
7a04396d7c80
438d8eba3c8a
dd3ecd87872b
aaa0d4ca226b
ac85f3f63d55
99150117b2dc
[1]+ Exit 1 docker stop $(docker ps -q)
[root@izf8z14idfp0rxiag38b06z temp]# docker ps -a;
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
完成删除已停用容器后再次删除镜像:
[root@ temp]# sudo docker rmi jc_tomcat-8.0.1:latest
Untagged: jc_tomcat-8.0.1:latest
Deleted: sha256:f55e749e8a07306392445c4e0b3f1f2ec982312aa39c4d9aa91cd0f5d1416164
Deleted: sha256:b58f7667292969a19d4f9b9978954da62730f3cbc38354149d8656f6cd56b6d2
Deleted: sha256:699b43733f3812534e015c0cd0442b969ac4e6163bce4251776591de81e03617
Deleted: sha256:b12bfa409d4b4feff3a47de0622f35a06806a0561113b074814850ec5911cde1
Deleted: sha256:661622a1a461d3923679ffa235927f58f7141372c477e5d52461436980962036
Deleted: sha256:86e2242dc20780f0edd9c3208a9f29bc09c8e2b3d98f2da4463709651b1aaf10
Deleted: sha256:69318a0cf6ab5791819751dfd70d5a44e259915b9d371a6f3232abde0c19dc9c
删除成功!!!