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

查看:39
本文介绍了如何删除旧的 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 容器修剪:

Since Docker 1.13.x you can use Docker container prune:

docker container prune

这将删除所有停止的容器,并且应该以相同的方式在所有平台上工作.

This will remove all stopped containers and should work on all platforms the same way.

还有一个Docker 系统修剪:

docker system prune

这将在一个命令中清理所有未使用的容器、网络、图像(悬空的和未引用的)以及可选的卷.

which will clean up all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes, in one command.

对于较旧的 Docker 版本,您可以将 Docker 命令与其他 Unix 命令串在一起以获得您需要的内容.以下是如何清理已使用数周的旧容器的示例:

For older Docker versions, 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天全站免登陆