在consul healthcheck运行后,状态为"Dead"的Docker容器

Gio*_*tti 14 docker consul

我正在使用consul的healthcheck功能,并且我不断获取这些"死"容器:

CONTAINER ID  IMAGE                   COMMAND              CREATED         STATUS              PORTS                                                                                                                                                                    NAMES
20fd397ba638  progrium/consul:latest  "\"/bin/bash -c 'cur 15 minutes ago  Dead
Run Code Online (Sandbox Code Playgroud)

什么是"死"容器?停止的容器何时变为"死"?

为了记录,我运行progrium/consul + gliderlabs/registrator图像+ SERVICE_XXXX_CHECK env变量来进行健康检查.它运行一个运行一个图像的健康检查脚本,每隔X秒,就像这样docker run --rm my/img healthcheck.sh

我对一般"死"意味着什么以及如何防止它发生感兴趣.另一个特殊的事情是我的死容器没有名字.

这是集装箱检查的一些信息:

  "State": {
        "Dead": true,
        "Error": "",
        "ExitCode": 1,
        "FinishedAt": "2015-05-30T19:00:01.814291614Z",
        "OOMKilled": false,
        "Paused": false,
        "Pid": 0,
        "Restarting": false,
        "Running": false,
        "StartedAt": "2015-05-30T18:59:51.739464262Z"
    },
Run Code Online (Sandbox Code Playgroud)

奇怪的是,只有每一个容器都会变得死亡并且不会被移除.

谢谢

编辑:查看日志,我发现了什么使容器停止失败:

  Handler for DELETE /containers/{name:.*} returned error: Cannot destroy container 003876e41429013e46187ebcf6acce1486bc5011435c610bd163b159ba550fbc: 
Driver aufs failed to remove root filesystem 003876e41429013e46187ebcf6acce1486bc5011435c610bd163b159ba550fbc: 
rename /var/lib/docker/aufs/diff/003876e41429013e46187ebcf6acce1486bc5011435c610bd163b159ba550fbc 
/var/lib/docker/aufs/ diff/003876e41429013e46187ebcf6acce1486bc5011435c610bd163b159ba550fbc-removing: 
device or resource busy
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

edit2:发现:https://github.com/docker/docker/issues/9665

Von*_*onC 14

2016年3月更新:问题9665刚刚被PR 21107关闭(可能是docker 1.11)
这应该有助于避免"驱动程序aufs无法删除根文件系统","设备或资源忙"问题.


原始答案2015年5月

如果容器声明,则死亡是一个,经过测试Container.Start()

if container.removalInProgress || container.Dead {
        return fmt.Errorf("Container is marked for removal and cannot be started.")
}
Run Code Online (Sandbox Code Playgroud)

停止失败时设置的死,为了防止容器被重新启动.

在可能的失败原因中,请参阅container.Kill().
这意味着kill -15并且kill -9都失败了.

// 1. Send a SIGTERM
if err := container.killPossiblyDeadProcess(15); err != nil {
    logrus.Infof("Failed to send SIGTERM to the process, force killing")
    if err := container.killPossiblyDeadProcess(9); err != nil {
Run Code Online (Sandbox Code Playgroud)

这通常意味着,正如OP提到的那样,繁忙的设备或资源,阻止进程被杀死.