bash/ shell/ docker/ docker-compose/ health-monitoring

In my docker-compose.yml (version - 2.3), I have setup a healthcheck for couple of services. Here is the relevant yml snippet -

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

Here is my authz_Startup.sh content -

#!/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 -

{
  "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. Also, I am able to see the 200 response on my browser much before the service is declared "unhealthy".

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. Apache has a reverse proxy configured to forward requests to individual docker containers. 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 ).

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.

I changed the healthcheck url to http://localhost:9000/authz/ping and it started working fine. 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.

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question how to turn bash command into docker(-compose) healthcheck Docker Healthcheck AND Operator docker compose: issue to start a container with a specific shell script Make $ docker compose a command for docker-compose Docker compose container exiting Docker: Why can't a simple Dockerfile HEALTHCHECK based on grepping be accepted by docker? docker-compose exec causes [Errno 2] No such file or directory: 'docker-compose': 'docker-compose' in docker container Filter docker-compose output Exec /bin/bash in Docker Compose Installing latest docker compose on Ubuntu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM