0

In unix-like shells, I can delete all exited containers in one command like this:

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

The bottom line is I use a command substitution $().

In Windows cmd environment, I have tried a few different ways:

  • >docker rm $(docker ps -a -q -f status=exited)
  • >docker rm %docker ps -a -q -f status=exited%
  • >docker rm `docker ps -a -q -f status=exited`
  • >docker rm (docker ps -a -q -f status=exited)
  • >for /F %i in ('docker ps -a -q -f status=exited') do docker rm %i => this already looks way too complicated for what I want to achieve, but I'd go for it if it worked

None of these work, the first four give me the following error:

unknown shorthand flag: 'a' in -a
See 'docker rm --help'.

The last one gives me:

invalid argument "status" for "-f, --filter" flag: bad format of filter (expected name=value)
See 'docker ps --help'.

The "inner" command alone works fine, though:

>docker ps -a -q -f status=exited
85cb933116d4
87425f5ee3f3

How can I achieve this in one command?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.