Menu Close

Docker – How to stop docker containers

Here, we will help you to understand how to stop docker containers. We use “docker stop container_name” command to stop the container.

docker stop” command can be used with various options to stop containers in docker.

Usage:

docker stop container_name_1

docker stop command with options:

docker stop [OPTIONS] CONTAINER_NAME_1  CONTAINER_NAME_2 ...

Options:

NameDefaultDescription
--time , -t10Seconds to wait for stop before killing it

How docker stop command works ?

  • When we stop container by using docker stop command, main process inside the container receive SIGTERM signal and after a grace period, It receives SIGKILL signal.
  • Here, you can change first signal i.e SIGTERM with STOPSIGNAL instruction in the container’s Dockerfile or you can use --stop-signal option during docker run.

Example:

rootMac@ABCD ~ % docker stop redis
redis

*** Check the state of redis container after stopping it.

rootMac@ABCD ~ % docker ps -a

CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS                       PORTS                NAMES

0a83ed486b91   redis:latest             "docker-entrypoint.s…"   5 minutes ago   Exited (0) 4 minutes ago                          redis

To learn more about docker, Please refer given below link:

https://www.techieindoor.com/

References:

https://en.wikipedia.org

Posted in docker

Leave a Reply

Your email address will not be published. Required fields are marked *