<p>If you see the logs, there's exactly 15s between the calls. Which is what you have configured in you docker compose file.</p>
<p>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):</p>
<ul>
<li>Don't use healthcheck, just add your logic in the <code>command</code> part</li>
<li>Setup a higher interval for your healthcheck</li>
</ul>
<p>Also, I have questions for you:</p>
<ul>
<li>Why do you want the healthcheck to be done only once?</li>
<li>What if you server goes down, don't you want to restart it?</li>
</ul>
<p>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.</p>

CC BY-SA 4.0
2021-03-05T01:33:52.010Z
2021-03-05T01:33:52.010Z
Akram Fares
<p>I have the following healthcheck condition for a nginx container inside my docker-compose.yml file:</p>
<pre><code>healthcheck:
  test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://front-service:80&quot;]
  interval: 15s
  timeout: 5s
  retries: 5
</code></pre>
<p>The problem is that I see in the logs continuous calls to <code>http://front-service:80</code> even after nginx is running fine.</p>
<pre><code>front-service    | 172.18.0.4 - - [02/Mar/2021:09:58:23 -0300] &quot;GET / HTTP/1.1&quot; 200 2611 &quot;-&quot; &quot;curl/7.64.0&quot; &quot;-&quot;
front-service    | 172.18.0.4 - - [02/Mar/2021:09:58:38 -0300] &quot;GET / HTTP/1.1&quot; 200 2611 &quot;-&quot; &quot;curl/7.64.0&quot; &quot;-&quot;
</code></pre>
<p>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.</p>

CC BY-SA 4.0
2021-03-02T22:19:15.250Z
It's a healtcheck with an interval of 15s ... The goal is to continually ensure the service is healthy [worth looking at the documentation](https://docs.docker.com/compose/compose-file/compose-file-v3/#healthcheck). I don't think docker has the notion of "start" lifecycle hook in itself.
Tensibai
CC BY-SA 4.0
2021-03-03T11:01:30.460Z
I have the same test in a RabbitMQ container and it does not log every single ping try.
Leandro Battochio
CC BY-SA 4.0
2021-03-03T11:08:41.777Z
I'm unsure of what you mean, the same curl test on the same front-service in the redis container ?
Tensibai
CC BY-SA 4.0
2024-10-30T14:47:07.967Z
In case it helps someone, there's a solution here:
https://github.com/docker-library/healthcheck/tree/master/rabbitmq
Petronella
<docker-compose><nginx>
Nginx healthcheck does not stop
Leandro Battochio
# Nginx healthcheck does not stop

(Asked by: username_0 on 2021-03-02)

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.

**Tags:** docker-compose, nginx

> **Comments:**
> **username_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](https://docs.docker.com/compose/compose-file/compose-file-v3/#healthcheck). I don't think docker has the notion of "start" lifecycle hook in itself.  
> **username_0**: I have the same test in a RabbitMQ container and it does not log every single ping try.  
> **username_1**: I'm unsure of what you mean, the same curl test on the same front-service in the redis container ?  
> **username_2**: In case it helps someone, there's a solution here: https://github.com/docker-library/healthcheck/tree/master/rabbitmq  

---

## 1 answers

### Answer by username_3 on 2021-03-05. Score: 2 | Accepted answer

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.


---

