Debug School

aswinp.achutham90@gmail.com
aswinp.achutham90@gmail.com

Posted on

Diff between docker stop and docker kill?

The docker stop command stops the container gracefully and provides a safe way out. If a docker stop command fails to terminate a process within the specified timeout, the Docker issues a kill command implicitly and immediately.
The docker kill command terminates the entry point process abruptly. The docker kill command causes an unsafe exit

docker kill:
`[root@localhost bin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16a5ba925596 httpd "httpd-foreground" 8 minutes ago Up 7 minutes 80/tcp aswin2
5c8327c8ce40 httpd "httpd-foreground" 8 minutes ago Up 2 minutes 80/tcp aswin1
2e41b8634ec5 hello-world "/hello" 3 hours ago Exited (0) 3 hours ago inspiring_hugle
[root@localhost bin]# docker kill aswin1
aswin1
[root@localhost bin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16a5ba925596 httpd "httpd-foreground" 8 minutes ago Up 7 minutes 80/tcp aswin2
5c8327c8ce40 httpd "httpd-foreground" 9 minutes ago Exited (137) 3 seconds ago aswin1

docker stop:

[root@localhost bin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16a5ba925596 httpd "httpd-foreground" 3 minutes ago Up 2 minutes 80/tcp aswin2
5c8327c8ce40 httpd "httpd-foreground" 3 minutes ago Up 53 seconds 80/tcp aswin1
2e41b8634ec5 hello-world "/hello" 3 hours ago Exited (0) 3 hours ago inspiring_hugle
[root@localhost bin]# docker stop aswin1
aswin1
[root@localhost bin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16a5ba925596 httpd "httpd-foreground" 3 minutes ago Up 2 minutes 80/tcp aswin2

2e41b8634ec5 hello-world "/hello" 3 hours ago Exited (0) 3 hours ago inspiring_hugle`

Top comments (1)

Collapse
 
pkpupri_358 profile image
prashant

Docker stop cmd:- Stop container gracefully i.e. first stop the child process of that container then stop the parent process and provide a safe way out.

Docker kill cmd:- stop container forcefully without informing the child process i.e generating a SIGKILL signal and terminate all the process abruptly.

[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c91a0f994f47 httpd "httpd-foreground" 9 minutes ago Up 9 minutes 80/tcp kind_meitner
66d23993e0e4 httpd "httpd-foreground" 10 minutes ago Up 10 minutes 0.0.0.0:81->80/tcp, :::81->80/tcp clever_leavitt
c213671a8288 httpd "httpd-foreground" 10 minutes ago Up 10 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp admiring_faraday
708a7964a45f httpd "httpd-foreground" 10 minutes ago Up 10 minutes 80/tcp romantic_kepler
b21cb4ba98f8 httpd "httpd-foreground" About an hour ago Up 38 minutes 80/tcp raj2
a5151e54aa53 httpd "httpd-foreground" About an hour ago Created objective_austin
[root@localhost ~]# docker kill c91a0f994f47
c91a0f994f47
[root@localhost ~]# docker stop 66d23993e0e4
66d23993e0e4
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c91a0f994f47 httpd "httpd-foreground" 10 minutes ago Exited (137) 40 seconds ago kind_meitner
66d23993e0e4 httpd "httpd-foreground" 11 minutes ago Exited (0) 5 seconds ago clever_leavitt
c213671a8288 httpd "httpd-foreground" 11 minutes ago Up 11 minutes 0.0.0.0:80->80/tcp, :: :80->80/tcp admiring_faraday
708a7964a45f httpd "httpd-foreground" 11 minutes ago Up 11 minutes 80/tcp romantic_kepler
b21cb4ba98f8 httpd "httpd-foreground" About an hour ago Up 39 minutes 80/tcp raj2
a5151e54aa53 httpd "httpd-foreground" About an hour ago Created objective_austin
[root@localhost ~]#