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.
docker stop container_name_1
docker stop command with options:
docker stop [OPTIONS] CONTAINER_NAME_1 CONTAINER_NAME_2 ...
|10||Seconds 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
SIGTERMsignal and after a grace period, It receives
- Here, you can change first signal i.e
STOPSIGNALinstruction in the container’s Dockerfile or you can use
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: