1

Docker批量删除已停止的容器

 1 year ago
source link: https://syxdevcode.github.io/2022/09/30/Docker%E6%89%B9%E9%87%8F%E5%88%A0%E9%99%A4%E5%B7%B2%E5%81%9C%E6%AD%A2%E7%9A%84%E5%AE%B9%E5%99%A8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Docker批量删除已停止的容器

2022-09-30Docker

500 1 分钟

#显示所有的容器,过滤出Exited状态的容器,取出这些容器的ID,
sudo docker ps -a|grep Exited|awk '{print $1}'

#查询所有的容器,过滤出Exited状态的容器,列出容器ID,删除这些容器
sudo docker rm `docker ps -a|grep Exited|awk '{print $1}'`
#删除所有未运行的容器(已经运行的删除不了,未运行的就一起被删除了)
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)

如何批量删除Docker中已停止的容器?-可以有多种方式


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK