瀏覽代碼

Set exit code of old running container as 137

Signed-off-by: Chun Chen <chenchun.feed@gmail.com>
Chun Chen 10 年之前
父節點
當前提交
b0b2f979c7
共有 2 個文件被更改,包括 17 次插入2 次删除
  1. 2 2
      daemon/daemon.go
  2. 15 0
      docs/reference/commandline/cli.md

+ 2 - 2
daemon/daemon.go

@@ -207,8 +207,8 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool) err
 
 
 	if container.IsRunning() {
 	if container.IsRunning() {
 		logrus.Debugf("killing old running container %s", container.ID)
 		logrus.Debugf("killing old running container %s", container.ID)
-
-		container.SetStopped(&execdriver.ExitStatus{ExitCode: 0})
+		// Set exit code to 128 + SIGKILL (9) to properly represent unsuccessful exit
+		container.SetStopped(&execdriver.ExitStatus{ExitCode: 137})
 
 
 		// use the current driver and ensure that the container is dead x.x
 		// use the current driver and ensure that the container is dead x.x
 		cmd := &execdriver.Command{
 		cmd := &execdriver.Command{

+ 15 - 0
docs/reference/commandline/cli.md

@@ -1845,6 +1845,21 @@ The currently supported filters are:
 
 
 This shows all the containers that have exited with status of '0'
 This shows all the containers that have exited with status of '0'
 
 
+##### Killed containers
+
+You can use a filter to locate containers that exited with status of `137` meaning a `SIGKILL(9)` killed them.
+
+    $ docker ps -a --filter 'exited=137'
+    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
+    b3e1c0ed5bfe        ubuntu:latest       "sleep 1000"           12 seconds ago      Exited (137) 5 seconds ago                       grave_kowalevski
+    a2eb5558d669        redis:latest        "/entrypoint.sh redi   2 hours ago         Exited (137) 2 hours ago                         sharp_lalande
+
+Any of these events a result in `137` status:
+
+* the `init` process of the container is killed manually
+* `docker kill` kills the container
+* Docker daemon restarts which kills all old running containers
+
 ## pull
 ## pull
 
 
     Usage: docker pull [OPTIONS] NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG]
     Usage: docker pull [OPTIONS] NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG]