Docker Community Forums

Share and learn in the Docker community.

How to check if the service is healthy

(Thschoen) #1


I created a service in my docker swarm (17.06.0-ce):

docker service create --mode=global --name=web nginx

When I check the service, i get this information:

docker service ls
ID              NAME   MODE      REPLICAS IMAGE       PORTS
6m8rro8rwtup    web    global    4/4      nginx:latest

How can I check if the service is completly healthy? I don’t want to check with docker ps the state on every node.
If I see preplicas 4/4, does it mean that all containers of my service on all nodes are healthy (also a defined healthcheck is checked)?
In that case I just can check the replicas?

if(replicas.equals("4/4")) {
   return "service is healthy;
} else {
   return "service is unhealthy";

(Werner Dijkerman) #2

Have you taken a look at “healthchecks” ? See and the options that starts with --health

(Thschoen) #3

I added a healthcheck to my dockerfile. I can check the status on every node with “docker ps my_application”, but I would like to check the status of the service, the command “docker service ps my_application” doesn’t tell me if my application is healty on every node.

(Mrhatken) #4

I am interested in this too. I think we need to define what a healthy service is in respect to the health of task (containers running) in that service.

With ps I can see that all services has the right number of tasks running but I cannot tell if those tasks are health without checking ps or logs.

It seems to me I have to find out the node for each task, then ssh there and inspect the docker container to check the health status of each task.