Home >Operation and Maintenance >Docker >How docker clears stopped containers

How docker clears stopped containers

王林
王林Original
2020-05-20 11:34:243720browse

How docker clears stopped containers

清除停止的容器有多种方法,如下:

方法一:显示所有的容器,过滤出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版本以后,可以使用如下命令删除孤立的容器

sudo docker container prune

推荐教程:docker教程

The above is the detailed content of How docker clears stopped containers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn