Hi guys,
I can't seem to get the healthcheck to work.
This is my docker-compose.yml
:
version: "3.8"
services:
traefik:
image: traefik:v2.3
container_name: traefik
command:
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --providers.docker=true
- --providers.docker.watch=true
- --providers.docker.exposedbydefault=false
- --api.insecure=true
- --certificatesresolvers.le.acme.email=dev@myapp.com
- --certificatesresolvers.le.acme.storage=/acme.json
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
- --certificatesresolvers.le.acme.tlschallenge=true
- --log=true
- --log.filepath=/var/log/traefik.log
- --log.level=ERROR
ports:
- 80:80
- 8080:8080
- 443:443
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./acme.json:/acme.json"
- "/var/log:/var/log"
- loadbalancerdata:/data
networks:
- web
restart: unless-stopped
myapp-1:
image: ${OLIMAGE}
container_name: myapp-1
environment:
- PORT=3000
- METEOR_SETTINGS
ports:
- 3000:3000
labels:
- traefik.enable=true
- traefik.http.routers.myapp.rule=Host(`prodnew.myapp.at`)
- traefik.http.routers.myapp.tls=true
- traefik.http.routers.myapp.tls.certresolver=le
- traefik.http.routers.myapp.entrypoints=websecure
- traefik.http.services.myapp.loadbalancer.server.port=3000
- traefik.http.services.myapp.loadbalancer.sticky=true
- traefik.http.services.myapp.loadbalancer.healthcheck.interval=10s
- traefik.http.services.myapp.loadbalancer.healthcheck.timeout=5s
volumes:
- /mnt/myapp_volume_01/olfiles:/files
depends_on:
- traefik
networks:
- web
healthcheck:
test: curl -f http://localhost:3000 || exit 1
interval: 20s
timeout: 10s
retries: 3
start_period: 10s
restart: unless-stopped
myapp-2:
image: ${OLIMAGE}
container_name: myapp-2
environment:
- PORT=3002
- METEOR_SETTINGS
ports:
- 3002:3002
labels:
- traefik.enable=true
- traefik.http.routers.myapp.rule=Host(`prodnew.myapp.at`)
- traefik.http.routers.myapp.tls=true
- traefik.http.routers.myapp.tls.certresolver=le
- traefik.http.routers.myapp.entrypoints=websecure
- traefik.http.services.myapp.loadbalancer.server.port=3002
- traefik.http.services.myapp.loadbalancer.sticky=true
- traefik.http.services.myapp.loadbalancer.healthcheck.interval=10s
- traefik.http.services.myapp.loadbalancer.healthcheck.timeout=5s
volumes:
- /mnt/myapp_volume_01/olfiles:/files
depends_on:
- traefik
networks:
- web
healthcheck:
test: curl -f http://localhost:3002 || exit 1
interval: 20s
timeout: 10s
retries: 3
start_period: 10s
restart: unless-stopped
autoheal:
image: willfarrell/autoheal
container_name: autoheal
restart: always
environment:
- AUTOHEAL_CONTAINER_LABEL=all
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- web
volumes:
loadbalancerdata:
networks:
web:
external: true
I then do the following: I have a function I call on one of my instances which invokes an infinite loop (while(true) {}
) ... causing the one instance to completely hangup and the node process to peak at 100% CPU.
As far as I understand it traefik should check my instances every 10 seconds and re-route me to the other working instance at some point (after 3 retries I guess). This never occurs:
No matter what I do, my instances always have the green checkmark and (I guess due to traefik.http.services.myapp.loadbalancer.sticky=true
) I never get routed to my other, still working instance - I just end up with an endless loading screen in my browser.
What do I have to do to make traefik remove my hung-up instance sooner than later and re-route all the traffic to the other, still working, instance?
What am I doing wrong? Please help!
Cheers, Patrick