Back to lessons

Hosting Operations

Check Container Health Status

You need to see health-check state without opening a full inspect dump.

Command

docker inspect --format '{{.Name}} health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}} status={{.State.Status}}' web

What changed

Nothing changes. Docker reads container state metadata.

Danger

safe

When to use it

Use when a container is running but the service still seems unavailable.

When not to use it

Do not use it as a full app check if the image has no HEALTHCHECK.

Undo or recovery

No undo needed because this command is read-only.

Expected output

/web health=healthy status=running

demo script

Disposable terminal steps

  1. docker inspect --format '{{.Name}} health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}} status={{.State.Status}}' web
  2. docker inspect --format '{{range .State.Health.Log}}{{.End}} {{.ExitCode}} {{.Output}}{{end}}' web

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ docker inspect --format '{{.Name}} health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}} status={{.State.Status}}' web
/web health=healthy status=running
::exit-code::0
$ docker inspect --format '{{range .State.Health.Log}}{{.End}} {{.ExitCode}} {{.Output}}{{end}}' web
/web health=healthy status=running
::exit-code::0

YouTube Short

Running is not healthy.

Running only means the process exists. If the image has a health check, print both Docker status and health status.

LinkedIn hook

Docker may say a container is running while its health check says otherwise.

Question: How often do you see running containers that are still unhealthy?

experiments

A/B tests to run

Metric: comment_rate

A: Running is not the same as healthy.

B: Docker status can lie by omission.