【问题标题】:Docker Healcheck with net core带有网络核心的 Docker Healcheck
【发布时间】:2019-08-03 01:21:43
【问题描述】:

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

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

我的步骤:

  • 我在 aspnetcore 项目中配置了健康检查端点。路径是/health
  • 然后我创建了 docker stuff 并将 HEALTHCHECK 属性设置为 official docs 中描述的
  • 当我运行容器时,我看到它的状态永久不健康

检查命令为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"
        }
    ]
}

我很绝望,所以我希望社区能帮助我解决问题

【问题讨论】:

标签: docker asp.net-core


【解决方案1】:

魔鬼在细节中

我从OCI runtime exec failed: exec failed: (…) executable file not found in $PATH": unknown 发现该命令必须不包含任何引号。

所以在 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

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    相关资源
    最近更新 更多