Docker

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.

About the author

Hitesh Jethva

Hitesh Jethva

I am Hitesh Jethva lives in Ahmedabad, INDIA. I am Linux system administrator and Technical writer.

I felt in love with Linux while i was started to learn Linux. I am a fan of open source technology and have more than 8+ years of experience in Linux and Open Source technologies. My main motto is to make uncomplicated things easier.

I have extensive experience within the following areas: CentOS/RHEL/FreeBSD/Ubuntu/Debian, cPanel/WHM, High Availability Architecture, Proactive security/Web Application Security, Amazon Web Services (AWS), Apache/Nginx, OpenLDAP, DevOps automation: Chef/Docker.

My expertise includes Linux system administration, installation, configuration, tuning, security and troubleshooting. I have large skills in configuring/management/support of Apache, Nginx, MariaDB, MongoDB, PHP-FPM, Nagios, Zabbix, Graylg, Redis, Docker and much more.