Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop all docker containers at once on Windows

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?

like image 983
Issa Fram Avatar asked Feb 15 '18 17:02

Issa Fram


People also ask

How do I kill all running docker containers?

Kill All Containers Using Docker Compose If you do, killing multiple containers takes one command: docker-compose down. You could also run docker-compose without detached mode. If so, you'll just use ^C to kill all containers. And there you have it—all containers killed!

How do I stop and delete all docker containers?

Stop and remove all containers The following command is convenient if you want to stop/remove all the containers, including the running container. In this command, docker ps -a -q is used to display a list of IDs of all Docker containers, and docker rm is used to delete them.


2 Answers

You could create a batch-file (.bat or .cmd) 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 can use this Linux command:

docker stop $(docker ps -q) 

Note: this will fail if there are no containers running

For PowerShell, the command is very similar to the Linux one:

docker ps -q | % { docker stop $_ } 
like image 190
huysentruitw Avatar answered Sep 19 '22 13:09

huysentruitw


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

docker ps -q | % { docker stop $_ } 
like image 37
greensmith Avatar answered Sep 19 '22 13:09

greensmith