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:
Name | Default | Description |
--time , -t | 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
SIGTERM
signal and after a grace period, It receivesSIGKILL
signal. - Here, you can change first signal i.e
SIGTERM
withSTOPSIGNAL
instruction in the container’s Dockerfile or you can use--stop-signal
option duringdocker 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