Assuming one wants to unconditionally remove all containers in a host, they would run:
$ docker rm -f $(docker ps -a -q)
Suppose now that you want to execute this in a remote host via ssh. The following won’t work:
$ ssh remote_user@remote_host "docker rm -f $(docker ps -a -q)"
because the $(docker ps -a -q)
part is expanded locally on your machine and you ssh remotely after the expansion. So at best it would seek to remove your local containers over there :)
What would work though? xargs
to the rescue:
$ ssh remote_user@remote_host "docker ps -a -q|xargs -n 1 docker rm -f "
Of course you can fine-tune further if you wish.