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.

Paul Knulst
Geek Culture

--

Photo by Online Marketing on Unsplash

Overview

1. Introduction
|
2. An example using Nginx
|
3. Why do we need a health check?
|
4. Configure a health check within the compose file
|
5. Often used Docker health checks
|--- 5.1 WGET
|--- 5.2 CURL
|--- 5.3 What to do if CURL/WGET is not available?
6. A custom health check
|
7. Closing Notes

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

--

--

Paul Knulst
Geek Culture

Husband, father of two, geek, lifelong learner, tech lover & software engineer. Writing about projects and challenges in IT. https://www.paulsblog.dev