📜  docker kill all containers windows - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:14:45.841000             🧑  作者: Mango

Docker Kill All Containers in Windows - Shell/Bash

Introduction

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.

Prerequisites
  • Docker for Windows installed and running
  • Basic knowledge of Shell/Bash commands
Steps
  1. Open the Docker Command Prompt by double-clicking the Docker icon on your desktop or by searching for it in the Start menu.

  2. 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.

  3. 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.

  4. 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.

Conclusion

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.