简体   繁体   English

码头工人撰写健康检查问题

[英]docker compose healthcheck issue

In my docker-compose.yml (version - 2.3), I have setup a healthcheck for couple of services. 在我的docker-compose.yml(版本-2.3)中,我为几个服务设置了运行状况检查。 Here is the relevant yml snippet - 这是相关的yml代码段-

      healthcheck:
        test: ["CMD-SHELL", "/secrets/authz_Startup.sh"]
        interval: 30s
        timeout: 30s
        retries: 3
        start_period: 300s 

Here is my authz_Startup.sh content - 这是我的authz_Startup.sh内容-

#!/bin/bash
HTTP_STATUS="$(curl -IL --silent https://myHost.com/authz/ping 2>/dev/null | head -n 1 | cut -d ' ' -f 2)";
if [ "$HTTP_STATUS" = "200" ]; then
    echo "Service started";
    exit 0;
else
    echo "***Service NOT started*** --> $HTTP_STATUS";  
    exit 1;
fi
exit;

However, when I run "docker-compose up" and then inspect the health check output using "docker inspect --format='{{json .State.Health}}' CONTAINER_ID | jq", I always get - 但是,当我运行“ docker-compose up”,然后使用“ docker inspect --format ='{{json .State.Health}}'CONTAINER_ID | jq”检查运行状况检查输出时,总是得到-

{
  "Status": "unhealthy",
  "FailingStreak": 16,
  "Log": [
    {
      "Start": "2018-03-10T16:05:18.361126144+05:30",
      "End": "2018-03-10T16:05:18.668852098+05:30",
      "ExitCode": 1,
      "Output": "***Service NOT started*** --> \n"
    },
    {
      "Start": "2018-03-10T16:05:48.676933885+05:30",
      "End": "2018-03-10T16:05:48.973643139+05:30",
      "ExitCode": 1,
      "Output": "***Service NOT started*** --> \n"
    }
  ]
}

I am however able to run this script from terminal and get "Service started" message. 但是,我可以从终端运行此脚本并获得“服务已启动”消息。 I am also able to see a "200 OK" response when I request the ping url from my browser and the typical response time is in ms. 当我从浏览器请求ping URL时,我还能够看到“ 200 OK”响应,并且典型的响应时间以毫秒为单位。 Also, I am able to see the 200 response on my browser much before the service is declared "unhealthy". 另外,在该服务被宣布为“不健康”之前,我能够在浏览器上看到200响应。

I am at my wits end trying to figure out whatever it is that I am not doing right. 我竭尽全力试图弄清楚我做错了什么。 Can someone please help me with this? 有人可以帮我吗?

Figured this out --> In my setup, I have 4 docker containers running tomcat servers on port 8080 and mapped to ports (9000, 9001, 9002 & 9003) and an Apache Webserver running on port 443 on my ubuntu (v16.04) server. 弄清楚了->在我的设置中,我有4个docker容器在端口8080上运行tomcat服务器并映射到端口(9000、9001、9002和9003),以及一个Apache Web服务器在ubuntu上的443端口上运行(v16.04)服务器。 Apache has a reverse proxy configured to forward requests to individual docker containers. Apache具有配置为将请求转发到各个Docker容器的反向代理。 This part works fine. 这部分工作正常。 Eg - I make a request to apache webserver ( https://myHost.com/authz/ping ) and the request forwards to the individual docker container ( http://myHost.com:9000/authz/ping ). 例如-我向Apache服务器发出请求( https://myHost.com/authz/ping ),该请求转发到单个Docker容器( http://myHost.com:9000/authz/ping )。

However, healthcheck apis run from within docker containers and all this while I was attempting to make this request --> https://myHost.com/authz/ping but the docker container is unable to connect to the Apache webserver running on the host machine and that is why it was failing. 但是,运行状况检查api从docker容器中运行,而当我尝试发出此请求时,所有这些都-> https://myHost.com/authz/ping但docker容器无法连接到主机上运行的Apache Web服务器机器,这就是为什么它失败了。

I changed the healthcheck url to http://localhost:9000/authz/ping and it started working fine. 我将运行状况检查URL更改为http:// localhost:9000 / authz / ping ,它开始正常工作。 So, this bit is now sorted but I still need to figure out some way to make services from within docker container, discover services running on host machines. 因此,现在对这部分进行了排序,但是我仍然需要找出某种方法来从docker容器中制作服务,发现在主机上运行的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM