0

I have the following healthcheck condition for a nginx container inside my docker-compose.yml file:

healthcheck:
  test: ["CMD", "curl", "-f", "http://front-service:80"]
  interval: 15s
  timeout: 5s
  retries: 5

The problem is that I see in the logs continuous calls to http://front-service:80 even after nginx is running fine.

front-service    | 172.18.0.4 - - [02/Mar/2021:09:58:23 -0300] "GET / HTTP/1.1" 200 2611 "-" "curl/7.64.0" "-"
front-service    | 172.18.0.4 - - [02/Mar/2021:09:58:38 -0300] "GET / HTTP/1.1" 200 2611 "-" "curl/7.64.0" "-"

Wouldn't the correct behaviour be that if the check succeeds, it stops pinging my frontend endpoint? I don't want it to keep pinging after it finds out that the server is alive.

3
  • 1
    It's a healtcheck with an interval of 15s ... The goal is to continually ensure the service is healthy worth looking at the documentation. I don't think docker has the notion of "start" lifecycle hook in itself. – Tensibai Mar 2 at 22:19
  • I have the same test in a RabbitMQ container and it does not log every single ping try. – Leandro Battochio Mar 3 at 11:01
  • I'm unsure of what you mean, the same curl test on the same front-service in the redis container ? – Tensibai Mar 3 at 11:08
1

If you see the logs, there's exactly 15s between the calls. Which is what you have configured in you docker compose file.

If you don't want it to keep pinging after it finds out that the server is alive, you have two options (which is not recommended to do):

  • Don't use healthcheck, just add your logic in the command part
  • Setup a higher interval for your healthcheck

Also, I have questions for you:

  • Why do you want the healthcheck to be done only once?
  • What if you server goes down, don't you want to restart it?

My recommendation is to keep this config as is because it does the work of checking for your service availability and will restart as needed and quickly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.