docker-swarmhealth-check

Docker container stuck in starting can't be pinged


(I am using docker swarm) I have a docker container running a kafka instance with a healthcheck checking if a topic called hc has been created. Because of that the docker node ps command shows the CURRENT STATE of the container as STARTING. I have another docker container which sole purpose is to initialize all needed topics including the hc topic. However with the healthcheck of the kafka container in place the initialization container can't even ping the kafka container. However when I change the kafka helthcheck to something immediately returning healthy the init container has no problems pining and doing its initialization.

Is this expected behavior because services in the STARTING state are not available on the network or something?

I was not able to find any documentation on this so please link me some if you are happen to find some.


Solution

  • The docker swarm service load balancer does not route traffic to containers that have not yet passed their health check.

    This means you health check must refer to localhost, not "Kafka" because, "kafka" based connection strings simply won't resolve until the health check passes for the first time.