【问题标题】:Use wget instead of curl for healthchecks in ASP.NET Core docker images在 ASP.NET Core docker 镜像中使用 wget 而不是 curl 进行健康检查
【发布时间】:2022-06-22 09:15:35
【问题描述】:

我想使用 ASP.NET Core 6 健康检查作为 docker 健康检查。

docs state:

使用基于 Alpine Linux 的镜像的容器可以使用包含的 wget 代替 curl

但是没有任何指导,而且像往常一样让 docker 配置“恰到好处”更像是一门艺术而不是一门科学。

我该怎么做?

【问题讨论】:

    标签: asp.net-core dockerfile asp.net-core-6.0 health-check


    【解决方案1】:

    首先请注意,ASP.NET Core docker images 默认公开 port 80,而不是 5000(因此问题中链接的文档不正确)。

    这是对非 Alpine 图像使用 curl 的典型方式:

    HEALTHCHECK --start-period=30s --interval=5m \
      CMD curl --fail http://localhost:80/healthz || exit
    

    但是 curl 在 Alpine 图像中不可用。不要安装它,而是使用wget:

    HEALTHCHECK --start-period=30s --interval=5m \
      CMD wget --spider --tries=1 --no-verbose http://localhost:80/healthz || exit 1
    

    HEALTHCHECK 切换:documented here

    wget 开关:--spider 阻止页面下载(类似于 HTTP HEAD),--tries=1 允许 docker 控制重试逻辑,--no-verbose(而不是 --quiet)确保记录错误由 docker 提供,以便您知道出了什么问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-17
      • 2017-06-09
      • 2020-09-19
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多