图像 traefik:1.6 的健康检查

healthcheck for the image traefik:1.6

如何构建一个 docker-compose 文件,其中包含图像 traefik:1.6 的健康检查,以验证容器是否健康?备注:图片没有cmd-shell权限。我不想更改图像的版本。

您可以使用 healthcheck command.

您必须激活 ping

在您必须在 docker-compose 文件中定义 healthcheck section 之后。

示例:

proxy:
  image: traefik:1.6
  command: --api --docker --ping
  ports:
    - "80:80"
    - "8080:8080"
  # ...
  healthcheck:
    test: ["CMD", "traefik" ,"healthcheck"]
    interval: 30s
    timeout: 3s
    retries: 30

对于traefik 1.7版本,healthcheck命令应该是./traefik healthcheck --ping。我 found it 经过与 traefik 参数的长期斗争。

希望对大家有所帮助。

image: traefik:1.7
command:
  - "--docker"
  - "--docker.swarmmode"
  - "--docker.watch"
  - "--ping"
  - "--loglevel=INFO"
healthcheck:
  test: ["CMD", "./traefik", "healthcheck", "--ping"]
  interval: 30s
  timeout: 3s
  retries: 30