Home » Uncategorized » How to Stop a Running Docker Container

How to Stop a Running Docker Container

In Docker, you can stop a running container using the docker stop command. This command sends a termination signal to the container, allowing it to gracefully shut down.

The following example shows how to stop a running Docker container.

Stop Running Docker Container Using Docker stop

To stop a running Docker container, you can use the docker stop command followed by the container ID or name.

Suppose we want to stop a container named app-postgres, we can run the following command in the terminal:

docker stop app-postgres

Output: 👇️

app-postgres

In this example, the docker stop command stops the container named app-postgres.

The command sends a SIGTERM signal to the main process inside the container, allowing it to perform any necessary cleanup before shutting down.

How to Verify the Stopped Container

To verify that the container has stopped, you can use the docker ps -a command.

Suppose we want to view all containers, including stopped ones, we can run the following command in the terminal:

docker ps -a

Output: 👇️

Verify Stopped Docker Container
Verify Stopped Docker Container

In this example, the docker ps -a command lists all containers, including the one we just stopped. The STATUS column shows that the container has exited.

In our example, we have stopped the container with the name app-postgress. The container STATUS column shows Exited.

Conclusion

We can stop a running Docker container using the docker stop command.

This allows us to gracefully shut down containers when they are no longer needed or when we need to perform maintenance tasks.