-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add HEALTHCHECK entry to Dockerfile to reliably monitor container readiness status #196
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
Comments
Yeah, especially for Compose this sounds excellent! |
Had a quick stab at this - I have a partial solution I think (hyleung@8f7fc32). The problem is that the way I've done the health check, it only works if the container is started with |
I think @yosifkit summarized adding
(some of that can be abated, such as trying to connect to the external IP of the container instead of |
I think the definition of "healthy" for a database can be agreed on by most as "ready to accept connections", but from the (very brief) look I had at the system, it doesn't quite fit with the way it's handled in Docker. |
How will this healtcheck stuff interact with kubernetes and other orchestration engines running on distributed systems? We aren't goint to trigger anything in case of unhealth, right? I think it may be usefult but not active by default (eg. we could distribute a healtcheck.sh but leave to the user the choice to enable it). |
@ioggstream I believe for Kubernetes, the health checks (readiness or liveness probes) are configured in the Podspec file (i.e. not baked into the container image) - http://kubernetes.io/docs/user-guide/liveness/. |
@hyleung yes, this kind of checks may interfere with orchestrators (I use openshift/kubernetes) so I'm for providing an "enabler", not to activate them by default. |
If in Dockerfile will be HEALTHCHECK line will Kubernetes have problem with it? If not, why block this feature because some orchestrator have own solution? |
Here is how to check from docker-compose: http://stackoverflow.com/questions/42567475/docker-compose-check-if-mysql-connection-is-ready/42757250#42757250 |
Hi @josephspurrier do you have the same solution when using mounted volume /docker-entrypoint-initdb.d and import big database (i need to wait fully import before start other container) Thx |
I've try this one and works fine :
Test if mysql command is running (when importing dump from /docker-entrypoint-initdb.d |
A fairly robust indication of the server's readiness is the presence of the .sock file, but image initialization will also do a temporary start of the server, so I've considered maybe having the entrypoint script write a simple flag file before the final startup, and having the image's healthcheck command check for both that file and the sock file. |
Are you sure this socketfile will be removed when server crashed or is not working? |
If it crashes (exits) the container will stop, but a hang would break this, yes. Running «mysqladmin ping» should work, though. |
The most reliable way I found is using an actual select query. The ping command will return when the MySQL server is started, but not when it's actually ready to handle queries. If you want to use it for a health check, you'll have to modify it a bit. while ! mysql -e "select 1" -u$MYSQL_USER -p$MYSQL_ROOT_PASSWORD >/dev/null 2>&1; do |
It seems the best healthcheck script is there: https://github.com/docker-library/healthcheck/blob/master/mysql/docker-healthcheck Any reason why not just copy it there? |
Those both require the script being able to authenticate, which is a very unreliable assumption. You only need to set the password the first time the container is started, and it's strongly recommended to change it right away. mysqladmin ping will return success if you get access denied, failure if the process is running but the server is not accepting connections |
Closing given that there's not a reliable way we can add this by default to the image, and there are now a decent number of examples for folks to build this for their own uses (matching their own valid assumptions per-environment). |
As of Docker release 1.12.0:
This feature will greatly facilitate start of dependent containers only after mysql container completes initialization, both manually and with Compose (after it becomes healthcheck-aware compose/#3754).
The text was updated successfully, but these errors were encountered: