Home > Blockchain >  Docker silent Healthcheck?
Docker silent Healthcheck?

Time:07-10

I want to add a healthcheck to my container, and it's working fine, but it's spamming my container log every time it checks, which is noisy and makes gleaning the important stuff out:

today at 12:44:38 AM127.0.0.1 - - [07/Jul/2022:00:44:37 -0500] "HEAD / HTTP/1.1" 200 427 "-" "curl/7.12.0 (x86_64-unknown-linux-gnu) libcurl/7.12.0 ipv6 zlib/1.2.3.4 libidn/1.23"

Every 30 seconds.

I want to have it continue working normally, minus the log spam. I've tried this so far, thinking I could send the output to > /dev/null, but no luck; it still sends to the container log (stdout):

HEALTHCHECK CMD curl -ILfSs http://localhost:80 -A "HealthCheck" > /dev/null || exit 1

Anyone know how to do this?

CodePudding user response:

Just following up on my question, I ended up doing this in Apache's 000-default (site config) file:

#   ---------------------------------------------------------------------------------------------------------------------------  
# | Prevent access.log spam of the Docker Healthcheck                                                                           |
# | Refs:                                                                                                                       |
# | https://httpd.apache.org/docs/2.2/mod/mod_setenvif.html                                                                     |
# | https://www.linuxquestions.org/questions/linux-server-73/need-to-exclude-certain-messages-from-apache-access_log-4175543280 |
#   ---------------------------------------------------------------------------------------------------------------------------  
<IfModule setenvif_module>
    # If UA matches healthcheck, set 'nolog' env var, which we exclude from the log(s) in the logformat section below.
    BrowserMatchNoCase ^healthcheck nolog
</IfModule>

CustomLog ${APACHE_LOG_DIR}/access.log combined env=!nolog

Note that I had set the custom health check UserAgent to: HealthCheck: Docker/1.0:

HEALTHCHECK CMD curl -ILfSs http://localhost:80 -A "HealthCheck: Docker/1.0" || exit 1

Thanks Hans, for pointing me in the right direction.

  • Related