How To Successfully Implement A Healthcheck In Docker Compose
Knowing if your Docker service is running correctly is important. A not running service can lead to a big incident! Learn how to use a Docker health check to guarantee that this does not happen to you.
1. Introduction
A health check is exactly what they sound like - a way of checking the health of a resource. In the case of Docker, a health check is used to determine the health of a running container.
When a health check command is created, it defines how a container can be tested to see if it is working correctly. With no health check defined, Docker cannot know whether or not the services running within your container are actually started or not.
While working with Docker, two ways of defining a health check exist:
- Dockerfile
- Docker-Compose file.
I will cover only Docker-Compose Healthchecks within this article.
2. An example using Nginx
Let’s see how health checks work by using a simple Nginx web service. To create a very simple website we need three files:
A docker-compose.very-simple-web.yml, a Dockerfile, and an index.html:
The three files must be saved in this structure

Now let’s create the service:
If you open a web browser to localhost you should see “Hello World”
3. Why do we need a health check?
🙌 Support this content
If you like this content, please consider supporting me. You can share it on social media, buy me a coffee, or become a paid member. Any support helps.
See the contribute page for all (free or paid) ways to say thank you!
Thanks! 🥰