I am new at Creating and Using Docker…but I am learning alot.
The one thing I am trying to do is come up with a “GENERIC HEALTH CHECK” that I can apply to my Docker Containers
I have tried many things such as: (I change the Port which the Container is using)
From my point of view there is no generic health check that is suitable for all containers.
Even the mentioned test: curl -f http://localhost:8000/ || exit 1might test three containers in one:
the webserver-container (where the healthcheck is used/started)
the PHP-container because the index.php is processed
the database-container because this index.php connects to the database-container
If this healthcheck failes your webserver-container is marked as “unhealthy” but you don’t know which container is the reason for this issue.
So you have to design a healthchecks for each of your containers:
for the webserver you might request a static ressource (maybe a text returned by the webserver itself without using any other container). Or you can check for the webserver-service’s status.
for the PHP-FPM-container you can configure a /ping-ressource which can be used similar to this test: SCRIPT_NAME=/ping SCRIPT_FILENAME=/ping REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000 || exit 1. If you need mor information I can post the steps to reproduce
for a MySQL-container the healthcheck might look similar to this: test: mysqladmin -p${MARIADB_ROOT_PASSWORD} ping -h localhost
There is no one-fits-all-healthcheck - you have to choose a healthcheck which is suitable for this container.
To find out why your healthcheck failes you might open a shell in the container, run the test-command manually and check the result. Or you might check the container’s logs if there is a hint why the healthcheck failes.
If this doesn’t help you might want to post the docker-compose.yml so others might try to reproduce the issue or spot an error in the yml-file?