Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
健康检查HAProxy docker容器出现问题_Docker_Docker Compose_Haproxy - Fatal编程技术网

健康检查HAProxy docker容器出现问题

健康检查HAProxy docker容器出现问题,docker,docker-compose,haproxy,Docker,Docker Compose,Haproxy,HAProxy提供了一个非常紧凑的debian版本,没有ping、wget、curl或其他需要验证的命令。如何使用docker compose健康检查,验证HAProxy是否已启动并正在运行?您将在传递给docker容器的HAProxy.cfg中配置健康检查。健康检查部分可能看起来像: frontend frontend_name ... use_backend healthcheck if { path_beg /health } backend healthcheck serv

HAProxy提供了一个非常紧凑的debian版本,没有ping、wget、curl或其他需要验证的命令。如何使用docker compose健康检查,验证HAProxy是否已启动并正在运行?

您将在传递给docker容器的HAProxy.cfg中配置健康检查。健康检查部分可能看起来像:

frontend frontend_name
  ...
  use_backend healthcheck if { path_beg /health }

backend healthcheck
  server disabled-server 127.0.0.1:1 disabled
  errorfile 503 /path/to/template.html
和健康检查模板文件:

HTTP/1.0 200 OK

Cache-Control: no-cache

Connection: close

Content-Type: text/plain


up

其工作原理是运行状况检查后端,例如,您可以通过您喜欢的路径/health从前端路由到该后端。错误文件指令不使用503响应,而是允许您返回自定义错误响应,在本例中为200。

类似的操作可能会起作用:

echo”“>/dev/tcp/${HOSTNAME}/${PORT}| |退出1


它正在使用bash内置的/dev/tcp来测试与您知道HAProxy应该运行的端口的连接,如果无法连接,将失败。

谢谢,@jmoney只是一些问题:1。模板文件的格式是什么?2.在哪里设置/health路径?另外,如何调用此URL,而不使用curl,例如?1。更新了答案,是html。2.在
frontend
部分,您将添加一个
use\u backend hhealthcheck if{path\u beg/health}
3。您试图从何处调用健康url?另一个码头集装箱?你可以在卷发上运行一个,或者从其他地方调用你的haproxy健康检查。我正在使用docker compose,但这不起作用,因为图像不包含curl,例如:healthcheck:test:curl--fail-s | | exit 1 interval:1m30s timeout:10s retries:3对,我不是建议您从haproxy服务器运行curl,而是从容器外部的某个位置运行curl。