A container health check is a command or script that Docker runs inside a container to check if the container is working properly. It helps to know if the app inside the container is healthy or needs attention.
Click to reveal answer
beginner
Which Dockerfile instruction is used to define a health check?
The HEALTHCHECK instruction is used in a Dockerfile to specify how Docker should test the container's health by running a command inside it.
Click to reveal answer
beginner
What does the HEALTHCHECK CMD command do?
It runs a command inside the container at regular intervals. If the command succeeds, the container is healthy. If it fails, Docker marks the container as unhealthy.
Click to reveal answer
beginner
What are the possible health statuses Docker can show for a container?
Docker can show three health statuses: starting (health check is running but not ready), healthy (container passed the health check), and unhealthy (container failed the health check).
Click to reveal answer
intermediate
How can health checks improve container management?
Health checks help automatically detect problems inside containers. This allows tools to restart unhealthy containers or alert users, making apps more reliable and easier to maintain.
Click to reveal answer
Which Dockerfile instruction defines a container health check?
ACMD
BHEALTHCHECK
CRUN
DEXPOSE
✗ Incorrect
The HEALTHCHECK instruction tells Docker how to test the container's health.
What does Docker do if a health check command fails?
AMarks the container as unhealthy
BStops the container immediately
CIgnores the failure
DRestarts the Docker daemon
✗ Incorrect
Docker marks the container as unhealthy if the health check command fails.
How often does Docker run the health check command by default?
AEvery 30 seconds
BEvery 5 minutes
CEvery 1 second
DEvery hour
✗ Incorrect
By default, Docker runs the health check every 30 seconds.
What is the purpose of the HEALTHCHECK CMD in a Dockerfile?
ATo start the container
BTo copy files into the container
CTo expose ports
DTo specify the command Docker runs to check container health
✗ Incorrect
HEALTHCHECK CMD defines the command Docker uses to test if the container is healthy.
Which health status means the container is still starting and health checks are not yet conclusive?
Aunhealthy
Bhealthy
Cstarting
Dstopped
✗ Incorrect
The 'starting' status means the container is initializing and health checks are in progress.
Explain how to add a health check to a Docker container using a Dockerfile.
Think about the Dockerfile instruction and what it does.
You got /5 concepts.
Why are container health checks important in managing Docker containers?
Consider how health checks help keep apps running smoothly.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a HEALTHCHECK in a Docker container?
easy
A. To restart the Docker daemon automatically
B. To update the container's image
C. To check if the container's application is running correctly
D. To increase the container's CPU usage
Solution
Step 1: Understand the role of HEALTHCHECK
The HEALTHCHECK instruction runs a command inside the container to verify if the app is working properly.
Step 2: Identify what HEALTHCHECK does not do
It does not restart Docker daemon, update images, or increase CPU usage.
Final Answer:
To check if the container's application is running correctly -> Option C
Quick Check:
HEALTHCHECK verifies app status = B [OK]
Hint: HEALTHCHECK tests app inside container, not Docker itself [OK]
Common Mistakes:
Confusing HEALTHCHECK with Docker daemon restart
Thinking HEALTHCHECK updates images
Assuming HEALTHCHECK changes resource usage
2. Which of the following is the correct syntax to add a health check in a Dockerfile?
easy
A. HEALTHCHECK CMD curl -f http://localhost/ || exit 1
B. HEALTHCHECK RUN curl -f http://localhost/ || exit 1
C. HEALTHCHECK EXEC curl -f http://localhost/ || exit 1
D. HEALTHCHECK CHECK curl -f http://localhost/ || exit 1
Solution
Step 1: Recall Dockerfile HEALTHCHECK syntax
The correct syntax uses HEALTHCHECK CMD followed by the command to run.
Step 2: Identify incorrect keywords
RUN, EXEC, CHECK are not valid keywords for HEALTHCHECK instruction.
But your container health status is always starting. What is the likely problem?
medium
A. The container has no network access
B. The HEALTHCHECK syntax is invalid
C. Docker daemon is not running
D. The health check command never succeeds within the start period
Solution
Step 1: Understand 'starting' health status meaning
'starting' means the container is still within the initial grace period before health checks are considered final.
Step 2: Analyze why health check stays 'starting'
If the command never succeeds during this period, Docker keeps status as 'starting'. Syntax is correct, Docker daemon running, and network likely accessible.
Final Answer:
The health check command never succeeds within the start period -> Option D
Quick Check:
Failing health check in start period = starting [OK]
Hint: Starting means health check not yet passed in grace period [OK]
Common Mistakes:
Assuming syntax error causes 'starting' status
Blaming Docker daemon when it runs fine
Ignoring network issues but they are less likely here
5. You want to create a health check that retries 3 times before marking unhealthy and waits 10 seconds between checks. Which Dockerfile snippet correctly sets this up?