Stop all docker containers at once on Windows

2019-03-25 03:45发布

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?

2条回答
何必那么认真
2楼-- · 2019-03-25 04:02

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)
查看更多
Explosion°爆炸
3楼-- · 2019-03-25 04:21

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

docker ps -q | % { docker stop $_ }
查看更多
登录 后发表回答