World map

 

BM: Baca dalam Bahasa Melayu

World D2: Recipes

HEALTHCHECK: is it alive?

You will learn: to let Docker check that your app still answers, not just that it runs.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

docker ps says your box is Up. But every page shows an error. Is it healthy?

Pick one answer.

Watch

The broken recipe checks /health every 5 seconds, a page that does not exist. After 20 seconds, docker ps shows web as Up (unhealthy). Docker transcript: $ cat broken/Dockerfile FROM nginx:1.30-alpine COPY index.html /usr/share/nginx/html/ HEALTHCHECK --interval=5s --timeout=3s \ CMD curl -fs http://localhost/health || exit 1 $ docker build -t diary:broken broken [+] Building 0.1s (7/7) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 189B 0.0s => [internal] load metadata for docker.io/library/nginx:1.30-alpine 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/2] FROM docker.io/library/nginx:1.30-alpine@sha256:0e52bd054126cdc0 0.0s => => resolve docker.io/library/nginx:1.30-alpine@sha256:0e52bd054126cdc0 0.0s => [internal] load build context 0.0s => => transferring context: 232B 0.0s => [2/2] COPY index.html /usr/share/nginx/html/ 0.0s => exporting to image 0.1s => => exporting layers 0.0s => => exporting manifest sha256:ebb36d6cd5640cbf03395a313040768dbb51a7aff 0.0s => => exporting config sha256:bbe5baeedf01d763862cfb832c17f0d5b47aec4f6b7 0.0s => => exporting attestation manifest sha256:1b63be82f7c2cf434f5bc40c06a58 0.0s => => exporting manifest list sha256:da97c645dd67971a5aa4403eb00b1a1e8c04 0.0s => => naming to docker.io/library/diary:broken 0.0s => => unpacking to docker.io/library/diary:broken 0.0s $ docker run -d --name web diary:broken a38f59ca5adda6bba9144b3c77a385d92916137599ce5190200680fc2b636181 $ sleep 20 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a38f59ca5add diary:broken "/docker-entrypoint.…" 26 seconds ago Up 26 seconds (unhealthy) 80/tcp web

Your laptop~/diary

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB

0 containers (0 running), 1 images, 0 lockers.

A HEALTHCHECK: A small test Docker runs again and again: is the app still answering? knocks every 5 seconds. Here it asks for /health, which does not exist. After 3 misses in a row, the status says unhealthy.

Try it

Build a check that knocks on the home page every 10 seconds.

Tap the pieces in the right order.

…

Try it

This recipe checks the home page. Build it, run it as web, wait a little, then look.

Your laptop~/diary

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB

0 containers (0 running), 1 images, 0 lockers.

Predict

web turns unhealthy. What does plain Docker do about it?

Pick one answer.

You did it!

You can now add a HEALTHCHECK and read the health status.

Go deeper (optional)

Defaults: every 30s, 30s timeout, 3 retries. --start-period gives a slow app time to wake up. Compose can wait for service_healthy (World D4). Kubernetes ignores HEALTHCHECK and uses its own probes (Part 3). Check / or a small /health page, never anything slow.

Real mission

  1. docker ps

0 of 3 steps done · Your ticks are saved.