Sub topic 6
Reading health status with docker ps and docker inspect
This chapter assumes you can build and run images, you know that a HEALTHCHECK runs a probe command on a schedule, and you know the three states: starting, healthy and unhealthy. Here you will read those states from a running container and find out why a probe failed.
Where health appears
Docker records health in two places. docker ps shows a short summary. docker inspect shows the full record, including the output of recent probes. Containers built from an image without a health check show neither.
Reading the STATUS column
Build the image from the Dockerfile with the Python probe, start a container, and list it:
docker build -t myapp .
docker run -d --name myapp -p 8000:8000 myapp
docker ps --filter name=myappRight after the start, the STATUS column reads like this:
Up 3 seconds (health: starting)Once a probe succeeds, it changes to:
Up 35 seconds (healthy)If the probe fails the configured number of times in a row, it changes to:
Up 2 minutes (unhealthy)Notice that starting is written as (health: starting), while the other two states appear without the word "health". A container with no health check shows only Up 2 minutes.
You can also filter by health. This lists only containers that need attention:
docker ps --filter health=unhealthyThe valid values are starting, healthy, unhealthy and none.
Reading the status with docker inspect
docker inspect reads the State.Health object. To print only the status, use a Go template:
docker inspect --format '{{.State.Health.Status}}' myappThis prints one word, such as healthy. That makes it handy in scripts, for example to wait until a container is ready. If the container has no health check, .State.Health does not exist and the template fails with an error. Check for that case in scripts.
To see everything Docker recorded, print the whole object as JSON:
docker inspect --format '{{json .State.Health}}' myappThe result has this shape:
{
"Status": "unhealthy",
"FailingStreak": 3,
"Log": [
{
"Start": "2026-12-04T10:15:02.114Z",
"End": "2026-12-04T10:15:02.231Z",
"ExitCode": 1,
"Output": "urllib.error.URLError: <urlopen error [Errno 111] Connection refused>"
}
]
}| Field | Meaning |
|---|---|
| `Status` | Current state: `starting`, `healthy` or `unhealthy`. |
| `FailingStreak` | Number of consecutive failed probes. It returns to 0 after a success. |
| `Log` | The most recent probe results, up to five. |
| `Log[].ExitCode` | The exit code of that probe. 0 means success and 1 means failure. |
| `Log[].Output` | What the probe wrote to stdout and stderr. |
The Log is the most useful part when debugging. The Output field shows the actual error your probe printed, such as a refused connection or a timeout. Docker stores only a limited amount of output per probe, so keep probe output short.
How the fields relate to the retry rule
FailingStreak explains why a container can have failing probes and still be healthy. With --retries 3, the status stays at its previous value until the streak reaches 3. One failed probe gives FailingStreak: 1 and no change in status. During the start period, failures do not count toward the streak, so a slow application is not marked unhealthy while it boots.
Watching changes over time
Health changes also produce events. To see them as they happen:
docker events --filter event=health_statusEach event carries the new status, so you can feed it into monitoring.
Exercise
A container shows Up 5 minutes (healthy) in docker ps, yet docker inspect reports FailingStreak: 2 and the retries value is 3. Is this a contradiction? What happens if one more probe fails?
Show answer
It is not a contradiction. The status changes to unhealthy only when the failing streak reaches the retries value. At a streak of 2 with retries 3, the container is still reported as healthy. If one more probe fails, the streak becomes 3 and the status changes to unhealthy. A single success before that would reset the streak to 0.
Exercise
Which command prints only the health status of a container named web, and what happens if the image has no HEALTHCHECK?
Show answer
docker inspect --format '{{.State.Health.Status}}' web. If no health check is defined, .State.Health is absent and the template produces an error instead of a status.