Stopping Containers in Docker Using the CLI Command

docker stop command
14 April 2025

Stopping Containers in Docker

Hello! Today we want to talk about one of the very useful Docker commands, namely the docker stop command. This command allows us to stop the containers that are currently running. You may have encountered situations where a container needs to be stopped due to reasons such as high resource consumption or performance issues. Using this command, we can easily turn off that container.

Before diving into the details of the command, it's best to understand what Docker is and what purpose it serves. Docker is a platform that provides developers the ability to run their applications in containers. Containers are a way to deploy and manage software applications and their dependencies. Therefore, you can easily run multiple software in one server.

Now, let's delve into the docker stop command. This command can help you easily stop one or several containers from a running state. You can stop a container using the container identifier (ID) or the names of the containers. For example, assume you have two containers named my_container1 and my_container2. With one command, you can stop both.

For this task, just a command in the following form is sufficient: You can use, of course, before using the docker stop command the docker ps command to view the currently running containers and identify the container you may want to stop.

Code Example

docker stop my_container1 my_container2.
docker stop $(docker ps -q)

Code Explanation


Line One: docker stop my_container1 my_container2 - This line stops containers named my_container1 and my_container2.
Line Two: docker stop $(docker ps -q) - With this line, all running containers will be simultaneously stopped. We use the command docker ps -q to retrieve the identifiers of the running containers.

FAQ

?

Why should I use the docker stop command?

?

How do I know which containers are running?

?

Can I stop multiple containers with one command?

?

If a container doesn't stop, what should I do?