Home:ALL Converter>Docker service health check is not working for spring boot application

Docker service health check is not working for spring boot application

Ask Time:2018-10-03T19:51:20         Author:Nitin

Json Formatter

I am running my spring boot web application as docker service and it is running fine without health check.

But when I tried to create docker service with health check options, my service gets restart automatically after some time (maybe after health heck timeout) and it never is stable.

I create \health rest endpoint and is simply return ok Here is command which I am using to create service with health check option and without it.

Command with health check option:

sudo docker service create \
    --health-cmd="curl --silent --fail localhost:8090/health || exit 1" \
    --health-interval=5s \
    --health-retries=12 \
    --health-timeout=2s \
    --health-start-period=60s \
    --name=my-service \
    -p "8090:8090" \
    my-docker-img

output:

s43fbah1qdlxb01s4x5veecos
overall progress: 0 out of 1 tasks 
1/1: starting  [============================================>      ] 

Command without health check:

sudo docker service create \
    --name=my-service \
    -p "8090:8090" \
    my-docker-img

My spring boot application takes 20s to up and running.

Author:Nitin,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52626437/docker-service-health-check-is-not-working-for-spring-boot-application
yy