Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

docker - 如何删除旧的Docker容器(How to remove old Docker containers)

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

(此问题与我是否应该担心多余的,未运行的Docker容器有关?)

.

(。)

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 3e552code34a可让您删除一个,但我已经有很多。)

docker rm --help doesn't give a selection option (like all, or by image name).

(docker rm --help没有提供选择选项(像所有选项一样,或按图像名称)。)

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

(也许有一个存储这些容器的目录,可以方便地手动删除它们?)

  ask by qkrijger translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...