Delete all the stopped containers (on Windows)?

Viewed 643

On Linux I can delete all of the stopped containers with this handy one-liner:

$ docker rm $(docker ps -a -q)

It's documented here: Remove all stopped containers

But what's the equivalent syntax for Windows?

2 Answers

You can use docker container prune to remove all stopped containers (or docker system prune to cleanup other unused resources, such as unused networks, unused images, etc.

More information can be found in the reference documentation for this command

In CMD terminal you can run:

FOR /f "tokens=*" %i IN ('docker ps -aq') DO docker rm %i

In Powershell terminal you can run:

docker ps -aq | % { docker rm $_ }

In Git Bash terminal you can run:

docker rm $(docker ps -aq)
Related