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?
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!
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.
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 $_ }
For those who are interested this can be accomplished in Powershell using
docker ps -q | % { docker stop $_ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With