Since Docker 1.13.x you can use Docker container prune :
(从Docker 1.13.x开始,您可以使用Docker容器prune :)
docker container prune
This will remove all stopped containers and should work on all platforms the same way.
(这将删除所有停止的容器,并且应在所有平台上以相同的方式工作。)
There is also a Docker system prune :
(还有一个Docker系统修剪 :)
docker system prune
which will clean up all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes, in one command.
(它将在一个命令中清除所有未使用的容器,网络,映像(悬空和未引用),以及可选的卷。)
For older Docker versions, you can string Docker commands together with other Unix commands to get what you need.
(对于较旧的Docker版本,可以将Docker命令与其他Unix命令一起使用以获取所需的内容。)
Here is an example on how to clean up old containers that are weeks old: (这是有关如何清理已使用数周的旧容器的示例:)
$ docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm
To give credit, where it is due, this example is from https://twitter.com/jpetazzo/status/347431091415703552 .
(为了得到应得的荣誉,此示例来自https://twitter.com/jpetazzo/status/347431091415703552 。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…