I am running a Spring Boot application within a Docker container, using the Docker file to start the application within the container. How can I check the health of the Spring Boot application within the container?
If the container stops or the application is not running, I need to restart the container or application automatically based on the health check. This way, I can ensure that the Spring Boot application will always be up and running.
LE GALL Benoît :
If you want to use the spring boot actuator/health as a docker healthcheck, you have to add it like this on your docker-compose file:\n healthcheck:\n test: "curl --fail --silent localhost:8081/actuator/health | grep UP || exit 1"\n interval: 20s\n timeout: 5s\n retries: 5\n start_period: 40s\n\nEdit:\nhere the port is the management.server.port. If you don't have specified it, it should be the server.port value (8080 by default)",
2019-12-17T22:39:56
Furetto :
this works for me\n healthcheck:\n test: curl -m 5 --silent --fail --request GET http://localhost:8080/actuator/health | jq --exit-status -n 'inputs | if has("status") then .status=="UP" else false end' > /dev/null || exit 1\n interval: 10s\n timeout: 2s\n retries: 10\n",
2021-02-22T13:16:33
Valerij Dobler :
My server does a redirect on index, so I use the redirect for health checks like so:\nhealthcheck:\n test: curl -Is localhost:8080 | head -n 1 | grep 302 || exit 1\n",
2022-02-25T22:25:00