How to stop a Docker container?

Published on Aug. 22, 2023, 12:19 p.m.

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

docker stop <container_id_or_name>

This command sends a SIGTERM signal to the container’s main process, allowing it to gracefully shut down before the container is actually stopped. If the container does not stop within a certain grace period (usually 10 seconds), docker stop will then send a SIGKILL signal to forcibly stop the container.

Alternatively, you can use the docker kill command to immediately stop the container by sending it a SIGKILL signal without any grace period:

docker kill <container_id_or_name>

Please keep in mind that stopping or killing a container may cause data loss if the container was not properly configured to persist data using data-only containers or volumes.

Tags: