NIK
NIK

Reputation: 1199

Podman how remove all exited containers if there are many

On a server running containers with Podman I just realised, there are many containers with "Exited" status and wanted to remove all of them in one go.

How can I do it with Podman?

Upvotes: 8

Views: 13148

Answers (2)

Tobias Nils Ackermann
Tobias Nils Ackermann

Reputation: 316

According to the official documentation there is a specific command for just that purpose:

Remove all stopped containers from local storage:

podman container prune

Upvotes: 18

NIK
NIK

Reputation: 1199

After searching for some time I found a quick and easy one liner to get my exited containers cleaned.

One option is:

podman rm -f $(podman ps -a -f "status=exited" -q)

The second option is:

podman ps -f status=exited --format "{{.ID}}" | xargs podman rm -f

A big thanks to dannotdaniel for the second option. This saved me at least an hour. :)

Upvotes: 7

Related Questions