Files
chill_notes/Docker/基础/如何批量删除Docker中已经停止的容器.md
2026-04-16 00:28:41 +08:00

28 lines
1.4 KiB
Markdown
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**方法一:**
==#====显示所有的容器,过滤出====Exited====状态的容器,取出这些容器的====ID======
==sudo docker ps -a|grep Exited|awk '{print $1}'==
==#====查询所有的容器,过滤出====Exited====状态的容器,列出容器====ID====,删除这些容器==
==sudo docker rm `docker ps -a|grep Exited|awk '{print $1}'`==
xx
**方法二:**
==#====删除所有未运行的容器(已经运行的删除不了,未运行的就一起被删除了)==
==sudo docker rm $(sudo docker ps -a -q)==
**方法三:**
==#====根据容器的状态,删除====Exited====状态的容器==
==sudo docker rm $(sudo docker ps -qf status=exited)==
**方法四:**
==#Docker 1.13====版本以后,可以使用== ==docker containers prune== ==命令,删除孤立的容器。==
==sudo docker container prune==
~~#~~~~删除所有镜像~~
~~sudo docker rmi $(docker images -q)~~
**附图:**
==02-====删除所有的容器,所有未运行的容器都被删除,正在运行的无法删除,达到删除不用容器的目的。==
==03-====低于====1.13====版本的====Docker====,可以根据容器的状态来进行删除==
==04-====查询所有的容器,过滤出状态为====Exited====的容器==
==05-Docker 1.13====版本以后,开始支持====prune====命令,快速删除已退出的容器==
> 来自 <[https://blog.csdn.net/jiangeeq/article/details/79499324](https://blog.csdn.net/jiangeeq/article/details/79499324)>