0
0
Spring Bootframework~10 mins

Health checks in Docker in Spring Boot - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Health checks in Docker
Start Docker Container
Docker runs Health Check Command
Health Check Command executes Spring Boot Actuator Endpoint
Spring Boot returns status (UP/DOWN)
Docker receives status
Docker marks container as healthy or unhealthy
Docker takes action based on health (restart, alert, etc.)
Docker runs a health check command that calls Spring Boot's actuator endpoint to get app status, then marks container health accordingly.
Execution Sample
Spring Boot
HEALTHCHECK --interval=10s --timeout=5s \
  CMD curl -f http://localhost:8080/actuator/health || exit 1
Docker runs this command every 10 seconds to check if the Spring Boot app is healthy.
Execution Table
StepActionCommand OutputDocker Health StatusContainer State
1Docker starts containerN/Astartingcontainer running
2Docker runs health check commandHTTP 200 {"status":"UP"}healthycontainer running
3Wait 10 secondsN/Ahealthycontainer running
4Docker runs health check commandHTTP 200 {"status":"UP"}healthycontainer running
5Wait 10 secondsN/Ahealthycontainer running
6Docker runs health check commandcurl: (7) Failed to connectunhealthycontainer running
7Docker marks container unhealthyN/Aunhealthycontainer running
8Docker restarts containerN/Astartingcontainer restarting
9Docker runs health check commandHTTP 200 {"status":"UP"}healthycontainer running
💡 Docker stops unhealthy state by restarting container after failed health check
Variable Tracker
VariableStartAfter 2After 4After 6After 8After 9
Docker Health Statusstartinghealthyhealthyunhealthystartinghealthy
Container Statecontainer runningcontainer runningcontainer runningcontainer runningcontainer restartingcontainer running
Key Moments - 3 Insights
Why does Docker mark the container unhealthy even though it is still running?
Docker bases health on the health check command result, not container running state. See step 6 in execution_table where command fails but container is still running.
What happens after Docker marks the container unhealthy?
Docker restarts the container to try to fix the problem, as shown in step 8 and 9 in execution_table.
Why use Spring Boot actuator endpoint for health check?
Because it returns a simple UP/DOWN status that Docker can easily interpret, shown in steps 2 and 4 where HTTP 200 with status UP means healthy.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Docker Health Status at step 4?
Astarting
Bunhealthy
Chealthy
Drestarting
💡 Hint
Check the 'Docker Health Status' column at step 4 in execution_table
At which step does the health check command fail causing Docker to mark the container unhealthy?
AStep 2
BStep 6
CStep 4
DStep 8
💡 Hint
Look for 'curl: (7) Failed to connect' in 'Command Output' column in execution_table
If the health check command always returns HTTP 200 with status UP, what will Docker do?
AKeep container healthy and running
BRestart container repeatedly
CMark container unhealthy
DStop the container
💡 Hint
Refer to steps 2 and 4 in execution_table where HTTP 200 means healthy
Concept Snapshot
Docker health checks run a command periodically.
Spring Boot actuator /health endpoint returns app status.
Docker marks container healthy if command succeeds.
If command fails, Docker marks unhealthy and can restart.
Use HEALTHCHECK in Dockerfile with curl to actuator.
This helps keep apps running smoothly.
Full Transcript
This visual execution shows how Docker performs health checks on a Spring Boot application. Docker starts the container and runs a health check command every 10 seconds. The command calls the Spring Boot actuator health endpoint. If the endpoint returns HTTP 200 with status UP, Docker marks the container healthy. If the command fails, Docker marks the container unhealthy but the container keeps running. After marking unhealthy, Docker restarts the container to recover. Variables like Docker Health Status and Container State change step by step. Key moments include understanding that health is based on the command result, not container running state, and that Docker restarts unhealthy containers. The visual quiz tests understanding of health status at different steps and Docker's reaction to health check results.