Requirements:
You must have Docker installed in order to run the commands shown in this article.
If you don’t have Docker installed, you may check the following articles on installing Docker to install Docker on your desired Linux distribution.
- How to Install and Use Docker on Ubuntu 18.04 LTS (https://linuxhint.com/install_docker_ubuntu_1804/)
- Install Docker on Debian 9 (https://linuxhint.com/install_docker_debian_9/)
- Install Docker on CentOS 7 (https://linuxhint.com/install-docker-centos7/)
- Install Docker on Raspberry Pi (https://linuxhint.com/install_docker_raspberry_pi/)
If you still have any problem installing Docker, you may contact me through https://support.linuxhint.com. I will be more than happy to help.
Stopping A Running Container:
You can stop any running Docker container on your Docker host. To stop a container, you need the ID or name of the container that you want to stop.
To get the container ID and name of all the running containers, run the following command:
As you can see the container ID and name of all the running containers are listed.
Now, let’s say, you want to stop the container www1 or c52585c7a69b.
To do that, you may run one of the following commands:
Or,
The container www1 or c52585c7a69b should be stopped.
Stopping All Running Containers:
You can also stop all the running Docker containers with a single command.
To stop all the running Docker containers, run the following command:
All the running Docker containers should be stopped.
Here, docker container list -q command returns the container ID of all the running Docker containers. Then the docker container stop command stops the containers using the container IDs.
As you can see, there is no running Docker containers in the list.
Again, you can see that all the running Docker containers are stopped.
Stopping All Docker Containers:
You can also stop any Docker containers regardless of their status (running, paused etc).
To stop all the Docker containers regardless of their status, run the following command:
All the Docker containers regardless of their status should be stopped.
Here, docker container list -qa command returns the container ID of all the Docker containers regardless of their status. Then the docker container stop command stops the containers using the container IDs.
You can verify whether the containers are stopped with the following command:
As you can see, all the containers are stopped.
So, that’s how you stop all the Docker containers on your Docker host. Thanks for reading this article.