gpt4 book ai didi

docker-compose 健康检查重试频率 != 间隔

转载 作者:行者123 更新时间:2023-12-03 21:29:09 63 4
gpt4 key购买 nike

我最近成立 healthcheck s 在我的 docker-compose配置。

它做得很好,我喜欢它。下面是一个典型的例子:

services:
app:
healthcheck:
test: curl -sS http://127.0.0.1:4000 || exit 1
interval: 5s
timeout: 3s
retries: 3
start_period: 30s

我的容器启动很慢,因此我设置了 30 秒 start_period .

但这并不符合我的期望:我不需要每 5 秒检查一次,但我需要知道容器何时为我的编排第一次准备好,因为我的 start_period是近似的,如果第一次检查还没准备好,我要等 interval在重试之前。

我想要的是:
  • 当容器不健康时,每 5 秒重试一次
  • 一旦健康,每 1 分钟检查一次

  • 没有办法通过 docker-compose 实现这种现成的?

    我可以编写一个自定义脚本来实现这一点,但如果可能的话,我宁愿有一个 native 解决方案。

    最佳答案

    不幸的是,这是不可能的。
    所有的持续时间设置都是最终的。它们不能根据容器状态进行更改。

    然而,根据documentation ,探针似乎没有等待start_period在检查您的测试之前完成。它唯一能做的就是在 start_period 期间发生任何故障。不会被视为错误。

    下面是让我想到的一句话:

    start_period provides initialization time for containers that need time to bootstrap. Probe failure during that period will not be counted towards the maximum number of retries. However, if a health check succeeds during the start period, the container is considered started and all consecutive failures will be counted towards the maximum number of retries.



    我鼓励您测试是否真的如此,因为我从未真正关注过是否在开始期间测试了健康检查。
    如果是这种情况,您可能可以增加您的 start_period如果您不确定持续时间并增加 interval为了找到一个好的妥协。

    关于docker-compose 健康检查重试频率 != 间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60038291/

    63 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com