0
0
Dockerdevops~30 mins

Health checks in Compose in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Health checks in Compose
๐Ÿ“– Scenario: You are setting up a simple web service using Docker Compose. To make sure your service is running correctly, you want to add a health check. This health check will help Docker know if your service is healthy or not.
๐ŸŽฏ Goal: Build a Docker Compose file that defines a web service with a health check. The health check will run a command inside the container to verify the service is working.
๐Ÿ“‹ What You'll Learn
Create a Docker Compose file with a service named web
Use the official nginx:alpine image for the web service
Add a health check to the web service that runs wget --no-verbose --tries=1 --spider http://localhost/
Set the health check interval to 10 seconds
Print the health status of the web service using docker compose ps
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Health checks help keep your applications running smoothly by letting Docker know if a service is working correctly. This is important in real projects to restart or replace failing containers automatically.
๐Ÿ’ผ Career
Understanding health checks in Docker Compose is useful for DevOps roles, site reliability engineers, and developers who deploy applications using containers.
Progress0 / 4 steps
1
Create the basic Docker Compose file
Create a file named docker-compose.yml with a service called web that uses the image nginx:alpine.
Docker
Need a hint?

Use the services key and define web under it with the image set to nginx:alpine.

2
Add a health check command
Add a healthcheck section under the web service with a test command that runs wget --no-verbose --tries=1 --spider http://localhost/.
Docker
Need a hint?

The test command should be an array starting with CMD followed by the wget command.

3
Set the health check interval
Add the interval key under healthcheck with the value 10s to run the health check every 10 seconds.
Docker
Need a hint?

The interval key controls how often the health check runs. Use 10s for 10 seconds.

4
Display the health status of the web service
Run the command docker compose ps in your terminal to see the health status of the web service.
Docker
Need a hint?

Use docker compose ps to check the status. The health column should show healthy after some time.