Doker

Stop Docker Containers

Stop Docker Containers
If you are a system administrator responsible for managing Docker, then you may need to know how to start and stop the Docker container. Stopping the Docker container is different from stopping any processes. To do so, you will need to use the “docker stop” command and specify the name or ID of the container that you want to stop.

This tutorial will show you how to stop Docker containers using several different methods.

Basic Syntax

The basic syntax to stop the Docker container is shown below:

docker container start [OPTIONS] CONTAINER [CONTAINER… ]

Or

docker container kill [OPTIONS] CONTAINER [CONTAINER… ]

Using the above syntax, you can stop one or more containers easily with a single command.

Stopping a Single Container

Before stopping any container, you will first need to find the ID or name of the Docker containers running on your system.

You can list all the Docker containers running on your system with the following command:

docker ps

After entering the above command, you should get the following output:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9392aab37f99 wordpress "docker-entrypoint.s… " About an hour ago Up
About an hour 0.0.0.0:8081->80/tcp wpcontainer
bcbc64840b0a mariadb "docker-entrypoint.s… " About an hour ago
Up About an hour 3306/tcp wordpressdb
3e5cddafb61d technosoft2000/calibre-web:v1.1.9 "/bin/bash -c /init/… "
20 hours ago Up About a minute 0.0.0.0:8082->8083/tcp calibre-web

Now, you will have have a list of all the Docker containers currently running, including the name and ID of every container.

Next, stop the Docker container named calibre-web or ID 3e5cddafb61d by running the following command:

docker container stop calibre-web

Or

docker container stop 3e5cddafb61d

You can also use the “kill” parameter instead of “stop” to stop the running Docker container, as shown below:

docker container kill calibre-web

Or

docker container kill 3e5cddafb61d

Next, to verify the status of the calibre-web container, enter the following command:

docker ps --filter "status=exited" | grep calibre-web

After entering the above command, you should get the below output:

3e5cddafb61d technosoft2000/calibre-web:v1.1.9 "/bin/bash
-c /init/… " 20 hours ago Exited (137) 33 seconds ago calibre-web

Stop Multiple Container

It is also possible to stop multiple containers using a single command.

For example, to stop the containers named “wpcontainer” and “wordpressdb,” run the following command:

docker container stop wpcontainer wordpressdb

Stopping All Running Containers

You can also stop all running containers using the “docker container ls -aq” option with the “docker container stop” command.

Run the following command to generate a list of all running containers and stop them.

docker container stop $(docker container ls -aq)

Verify all stopped containers with the following command:

docker ps --filter "status=exited"

After entering the above command, you should get the following output:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
592b9fe9f478 drupal "docker-php-entrypoi… " 2 hours ago Exited (0)
25 seconds ago mystifying_cartwright
9392aab37f99 wordpress "docker-entrypoint.s… " 2 hours ago Exited (128)
17 minutes ago 0.0.0.0:8081->80/tcp wpcontainer
bcbc64840b0a mariadb "docker-entrypoint.s… " 2 hours ago Exited (0)
25 seconds ago wordpressdb
3e5cddafb61d technosoft2000/calibre-web:v1.1.9 "/bin/bash -c /init/… "
21 hours ago Exited (137) 16 seconds ago calibre-web

Conclusion

In the guide provided by this article, you learned how to stop running Docker containers using several different methods. You can use whichever method works best for you to stop Docker containers from running.

Gry Open Source Ports of Commercial Game Engines
Open Source Ports of Commercial Game Engines
Free, open source and cross-platform game engine recreations can be used to play old as well as some of the fairly recent game titles. This article wi...
Gry Najlepsze gry wiersza poleceń dla systemu Linux
Najlepsze gry wiersza poleceń dla systemu Linux
Wiersz poleceń jest nie tylko twoim największym sprzymierzeńcem podczas korzystania z Linuksa - może być również źródłem rozrywki, ponieważ możesz go ...
Gry Najlepsze aplikacje do mapowania gamepada dla systemu Linux
Najlepsze aplikacje do mapowania gamepada dla systemu Linux
Jeśli lubisz grać w gry na Linuksie za pomocą gamepada zamiast typowego systemu wprowadzania klawiatury i myszy, jest kilka przydatnych aplikacji dla ...