Would anyone know of a good way to test healthcheck for a docker container without developing a custom method/route to kill an app in a container while maintaining container health? I want to ensure that a healthcheck will properly mark a container as unhealthy.
There is an option to add it as an instruction into the dockerfile
The instruction can be specified as
HEALTHCHECK <options> CMD <command>
Then you can add the HEALTHCHECK instruction, by using curl to ensure that our app is serving traffic on the right specified port used.
By adding this line to the Dockerfile right before the last line (CMD). For example
HEALTHCHECK CMD curl --fail <http://localhost:<portnumber>/|http://localhost:<portnumber>/> || exit 1
Then when you run docker ps command, you will find status(health check), noting that the health status appears only when a health check is configured.
Hope this helps!