Stop all docker containers at once on Windows

2019-03-25 03:32发布

问题:

How can I stop all docker containers running on Windows?

docker stop is for 1 container only.

Any command/script to make it stop all containers?

回答1:

You could create a batch (.bat) file with these commands in it:

@ECHO OFF
FOR /f "tokens=*" %%i IN ('docker ps -q') DO docker stop %%i

If you want to run this command directly in the console, replace %%i with %i, like:

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

In Git Bash or Bash for Windows you could run:

docker stop $(docker ps -q)


回答2:

For those who are interested this can be accomplished in Powershell using

docker ps -q | % { docker stop $_ }