📅  最后修改于: 2023-12-03 15:14:45.841000             🧑  作者: Mango
If you are a Docker user on Windows, you might face the issue of having too many running containers consuming your machine's resources. To stop all running containers simultaneously, you can use the docker kill
command.
This guide will walk you through the steps to kill all containers using Shell/Bash commands in Windows.
Open the Docker Command Prompt by double-clicking the Docker icon on your desktop or by searching for it in the Start menu.
Once the Docker Command Prompt is open, run the docker ps -q
command to list all running container IDs.
$ docker ps -q
This will output the list of running container IDs. If you want to confirm the container names as well, use the docker ps
command without the -q
option.
To stop all running containers, use the following command:
$ docker kill $(docker ps -q)
This command will use the output of the docker ps -q
command as input to the docker kill
command. The $(...)
syntax is called command substitution, and it will replace the contents between the parentheses with the output of the enclosed command.
Once the command finishes executing, you can verify that all containers are stopped by running the docker ps
command:
$ docker ps
This should output an empty list since all containers have been stopped.
In this guide, we have shown you how to use Shell/Bash commands in Windows to kill all running Docker containers. This is a handy command to know if you need to free up system resources or if you need to start fresh with a new set of containers.