Search code examples
linux-containerspodmanredhat-containers

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?


Solution

  • 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. :)