-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker compose health check #167
Comments
Did you find a solution for this ? doing something like this could work in the container :
Don't know if there is a better way ... the unset is needed when you've enabled JMX. |
We're facing this issue with Kubernetes. Our solution was to include a health-check.sh in our Dockerfile with the following, which goes to zookeeper and checks to see if the active brokers list returned contains the broker id of the node. It's not perfect - I'd rather directly query the node if it's up - but I don't see a way to do this and (at least in our case) Kubernetes is watching the Zookeeper cluster as well in a StatefulSet so it seems relatively safe to me. If there's general interest and @wurstmeister is into it I'd be willing to make a PR for this.
|
@alfreddatakillen - The document you reference just explains how to wrap your startup process in an external script / shell call (https://docs.docker.com/v1.10/compose/startup-order/) I assume you meant to reference https://docs.docker.com/compose/compose-file/#healthcheck - this was added in 1.12? However, this only reports the status of the container and does not block downstream dependencies. I believe this was mainly added for swarm support / restart policies e.g.
This is only useful for reporting status of container. Kafka will be started immediately after Zookeeper regardless of 'healthy state'.
@knordstrom - the healthcheck case may work OK for k8s if it was added to the docker image. |
For future visitors that cannot get @knordstrom healthcheck to work, this is how I solved it: Make sure that the shell script is added to a directory by your dockerfile. We're using dynamic IDs generated by zookeeper, so I had to use following healthcheck.sh:
Finally, add following code to your docker-compose:
|
There's a very nice solution here: confluentinc/cp-docker-images#358 (comment) |
That is only for zookeeper, it doesn't help for checking when Kafka is up and ready. |
Ah you are right, sorry. I must have mixed this issue up with another one. |
@Lukkie @dobesv @matthew-d-jones @sscaling @knordstrom @ddewaele @alfreddatakillen Hi, Your solution seems good but I am unable to get it working unfortunately. My kafka setup do not wait for the status to be OK in order to launch the commands !
When I check for Health Logs: First time:
And then:
And the errors returned from my kafka-setup service:
Means that the commands launched before getting the OK status from Healthcheck. How did you able to get it working please ? Thank you all ! |
This seems to work ok for me for checking whether Kafka is up or not:
(Note that I personally have Kafka running on port 9091, not 9092.) It's basic but it seems to be good enough to keep my other containers from starting up before Kafka is actually ready to start receiving traffic. |
This healthcheck works perfect for me:
|
healthcheck:
test: ["CMD-SHELL", "pgrep -f 'kafka.*9101' || exit 1"]
interval: 2m
timeout: 10s
retries: 3 |
Also better option is to use
|
Here is the solution for quay.io/debezium/kafka:2.5. Debezium won't install nc.
|
Here is how I did it in docker compose.Consider giving it a star if it was useful to you. |
docker-compose now supports health checks (since version 1.10.0), and delaying start-up of containers until their dependencies are up and healthy. See https://docs.docker.com/compose/startup-order/ for docs on this.
It would be great with an example of how to configure such health checks on a kafka container!
The text was updated successfully, but these errors were encountered: