如何清除旧的Docker容器 [英] How to remove old Docker containers

查看:193
本文介绍了如何清除旧的Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与相关我担心多余的,不运行的Docker容器?

This question is related to Should I be concerned about excess, non-running, Docker containers?.

我想知道如何清除旧容器。 docker rm 3e552code34a 允许您删除单个,但我已经有很多。 docker rm --help 不给出选择选项(像全部或图像名称)。

I'm wondering how to remove old containers. The docker rm 3e552code34a lets you remove a single one, but I have lots already. docker rm --help doesn't give a selection option (like all, or by image name).

也许存在这些容器存储的目录,我可以手动删除这些容器?

Maybe there is a directory in which these containers are stored where I can delete them easily manually?

推荐答案

有一个新功能 Docker 1.13.x 称为 Docker容器修剪。这样做将会像你想要的一样,应该在所有平台上都是一样的。

There is a new feature in Docker 1.13.x called Docker container prune. This will do what you want and should work on all platforms the same way.

还有一个 Docker系统修剪,它将通过一个命令清理容器,映像,卷和网络。

There is also a Docker system prune, which will clean up containers, images, volumes, and networks all in one command.

原始答案

有一些关于Docker清理命令的讨论。您可以在此机票上找到相关信息: https://github.com/dotcloud/docker/issues/ 928

There has been some talk about a Docker cleanup command. You can find the information on this ticket: https://github.com/dotcloud/docker/issues/928

直到该命令可用,您可以将Docker命令与其他Unix命令一起进行匹配,以获得所需的内容。以下是关于如何清理几个旧旧容器的示例:

Until that command is available, you can string Docker commands together with other Unix commands to get what you need. 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

要给予信用,到哪里,此示例来自 https://twitter.com/jpetazzo/status/347431091415703552

To give credit, where it is due, this example is from https://twitter.com/jpetazzo/status/347431091415703552.

这篇关于如何清除旧的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆