Docker静默运行状况检查?

hlswsv35  于 2023-03-29  发布在  Docker
关注(0)|答案(1)|浏览(123)

我想添加一个healthcheck到我的容器中,它工作正常,但每次检查时它都会发送垃圾邮件给我的容器日志,这很吵,并且使收集重要的东西变得比需要的更困难:

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"

每30秒一次。
我想让它继续正常工作,减去日志垃圾邮件。它仍然发送到容器日志(stdout):

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

有人知道怎么做吗?

balp4ylt

balp4ylt1#

为了回答我的问题,我最终在Apache的000-default(站点配置)文件中这样做:

# + --------------------------------------------------------------------------------------------------------------------------- +
# | 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

请注意,我已将自定义运行状况检查UserAgent设置为:HealthCheck: Docker/1.0

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

谢谢你,汉斯,为我指明了正确的方向。

相关问题