How can I build a docker-compose file with the healthcheck for the image traefik:1.6 to validate if the container is healthy? Remarks: The image does not have cmd-shell access. I would not like to change the version of the image.
How can I build a docker-compose file with the healthcheck for the image traefik:1.6 to validate if the container is healthy? Remarks: The image does not have cmd-shell access. I would not like to change the version of the image.
You can use the healthcheck command.
You have to activate the ping.
After you have to define a healthcheck section in your docker-compose file.
example:
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
For traefik version 1.7, the healthcheck command should be ./traefik healthcheck --ping. I found it after a long struggle period with traefik parameters.
Hope it helps somebody.
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
For traefik v2. You just have to enable the ping command
traefik:
image: traefik:2.7
command:
- --ping=true
# ...
ports:
- target: 80
published: 80
protocol: tcp
mode: host
- target: 443
published: 443
protocol: tcp
mode: host
# ...
healthcheck:
test: ["CMD", "traefik", "healthcheck", "--ping"]
interval: 5s
retries: 3