厨师 docker_container 使用 health_check

发布于 2025-01-18 20:41:28 字数 759 浏览 2 评论 0原文

我正在尝试在Chef中使用Health_check Docker功能,但是我遇到以下错误:

had an error: Docker::Error::ClientError: Interval in Healthcheck cannot be less than 1ms

我有以下厨师配置:

docker_container my_contianer do
  command container_command
  action :run
  repo repo
  tag tag
  user 'app'
  restart_policy 'always'
  env envs
  volumes volumes
  port [
    "80:8000"
  ]
  memory max_container_memory
  if container_config.key?('health_check')
    health_check(
      'Test' =>
        [
          'curl localhost:8000/health || exit 1',
        ],
      'Interval' => 30,
      'Timeout' => 10,
      'Retries' => 10,
      'StartPeriod' => 0
    )
  end
end

我也尝试了“ 30s”,但它不起作用,任何想法我应该如何使用此health_check函数?

I am trying to use the health_check docker feature in chef, but I am getting the following error:

had an error: Docker::Error::ClientError: Interval in Healthcheck cannot be less than 1ms

I have the following chef config:

docker_container my_contianer do
  command container_command
  action :run
  repo repo
  tag tag
  user 'app'
  restart_policy 'always'
  env envs
  volumes volumes
  port [
    "80:8000"
  ]
  memory max_container_memory
  if container_config.key?('health_check')
    health_check(
      'Test' =>
        [
          'curl localhost:8000/health || exit 1',
        ],
      'Interval' => 30,
      'Timeout' => 10,
      'Retries' => 10,
      'StartPeriod' => 0
    )
  end
end

I also tried '30s' and it did not work, any idea how should I use this health_check function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月竹挽风 2025-01-25 20:41:28

基本上我通过以下方式实现了它:

docker_container my_docker do
  command container_command
  action :run
  repo repo
  tag tag
  user 'app'
  restart_policy 'always'
  env envs
  volumes volumes
  port [
    "80:8000"
  ]
  memory max_container_memory
  if container_config.key?('health_check')
    # Running every 30 seconds
    # each time tries for 10 times with delay of 30s if after 10 times fails it will restart the docker
    health_check({
      'Test': [
        'CMD-SHELL',
        'curl -f --retry 10 --max-time 10 --retry-delay 30 --retry-max-time 20 -f localhost:8000/health || kill 1'
      ],
      'Interval': 30000000000,
      'Timeout': 1000000000,
      'Retries': 3
    })

  end

Basically I managed to achieve it by the following:

docker_container my_docker do
  command container_command
  action :run
  repo repo
  tag tag
  user 'app'
  restart_policy 'always'
  env envs
  volumes volumes
  port [
    "80:8000"
  ]
  memory max_container_memory
  if container_config.key?('health_check')
    # Running every 30 seconds
    # each time tries for 10 times with delay of 30s if after 10 times fails it will restart the docker
    health_check({
      'Test': [
        'CMD-SHELL',
        'curl -f --retry 10 --max-time 10 --retry-delay 30 --retry-max-time 20 -f localhost:8000/health || kill 1'
      ],
      'Interval': 30000000000,
      'Timeout': 1000000000,
      'Retries': 3
    })

  end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文