Stop a docker container:
The docker engine provides a stop option which can be used to stop the execution of a container which is in running state.
The syntax is as follows:
# docker stop <CONTAINER-NAME | CONTAINER-NAME ID
vamshi@node03:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33de85aaf61c 9a0b6e4f0956 “sh” 6 months ago Up About an hour do_nothing_container
Now we use the stop option to stop the running container.
vamshi@node03:~$ sudo docker stop do_nothing_container
do_nothing_container
The other arguments stop option accepts in –time or -t which stops the container in specified amount of time in seconds.
vamshi@node03:~$ sudo docker -v stop -t 20 do_nothing_container
do_nothing_container
vamshi@node03:~$ sudo docker ps -a | grep do_nothing
33de85aaf61c 9a0b6e4f0956 “sh” 6 months ago Exited (137) About a minute ago do_nothing_container
Once the command is typed the cli goes into non-interactive mode till the times expires and finally returns back after the container is successfully stopped; The container is killed and moved to the stopped state.
You can also read Managing Dock Disk Space