liveBook · Manning

Healthcheck instruction

As explained in Learn Docker in a Month of Lunches, Second Edition

The HEALTHCHECK instruction is a Dockerfile instruction that defines a command and scheduling parameters for testing an application's health in a container.

A running container can appear healthy while its application returns errors. HEALTHCHECK adds an in-container command that Docker runs at intervals and uses its status code to mark the container healthy or unhealthy. section 8.1

Check an HTTP health endpoint

Add `HEALTHCHECK CMD curl --fail http://localhost:8080/health` to a Dockerfile. The endpoint returns success while the API works and failure after the application breaks; Docker then records the unhealthy state while leaving the container running.

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains command execution, intervals, status codes, repeated failures, and inspection, but does not enumerate scheduling options.
Examples
Uses a .NET random-number API, a curl request to `/health`, deliberate failures, container listings, and inspection logs.
What it assumes
Assumes basic Dockerfile editing and Docker image or container commands while demonstrating the health-check workflow directly.
What you can do after
Operate/configure containers with an HTTP health command and diagnose application failure through Docker status and logs.
How it connects
Connects Dockerfile instructions with container runtime status, curl, HTTP health endpoints, and application process monitoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.