首页 > 解决方案 > 带有网络核心的 Docker Healcheck

问题描述

我遇到了一个问题。问题是该docker ps命令将我的容器的健康状态始终显示为不健康

我已经复制了这个问题并推送到 Github:https ://github.com/korenb/docker-healthcheck-aspnetcore.git

我的步骤:

检查命令是curl --fail http://localhost/health || exit 1

我很惊讶,如果我运行该命令,docker exec <container> curl --fail http://localhost/health那么它可以工作

我得到了一些日志,docker inspect <container>但我真的不知道出了什么问题。

{
    "Status": "unhealthy",
    "FailingStreak": 22,
    "Log": [{
            "Start": "2019-03-12T13:27:51.570474Z",
            "End": "2019-03-12T13:27:51.6708017Z",
            "ExitCode": -1,
            "Output": "OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused \"exec: \\\"curl --fail http://localhost/health || exit 1\\\": stat curl --fail http://localhost/health || exit 1: no such file or directory\": unknown"
        },
        {
            "Start": "2019-03-12T13:27:53.8550082Z",
            "End": "2019-03-12T13:27:53.9882208Z",
            "ExitCode": -1,
            "Output": "OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused \"exec: \\\"curl --fail http://localhost/health || exit 1\\\": stat curl --fail http://localhost/health || exit 1: no such file or directory\": unknown"
        }
    ]
}

我很绝望,所以我希望社区能帮助我找出问题所在

标签: dockerasp.net-core

解决方案


细节决定成败

我从OCI 运行时 exec failed: exec failed: (...) executable file not found in $PATH": unknown that command must be clean of any引号周围发现。

所以在 dockerfile 我替换了这个

HEALTHCHECK ... CMD ["curl --fail http://localhost/health || exit 1"]

这样

HEALTHCHECK ... CMD curl --fail http://localhost/health || exit 1

你可以在这里看到它https://github.com/korenb/docker-healthcheck-aspnetcore/commit/6a24b394b9d60bab75d2b7daf549aa86576c2bb5


推荐阅读