brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker inspect tells you if a container is healthy, not just running

Docker
~/tips/tip-docker-inspect-health

docker inspect --format '{{.State.Health.Status}}' mycontainer

Prints the health status of a container, so you can tell a stuck app from one that is working.

A container that says “Up” is not always a container that works. If the image defines a healthcheck, Docker keeps a separate verdict, and one command shows it.

Replace mycontainer with the name from docker ps:

docker inspect --format '{{.State.Health.Status}}' mycontainer

You get starting, healthy or unhealthy. docker ps shows the same thing in brackets behind the status, but the inspect form is useful in scripts and in a quick watch.

The caveat: a container without a healthcheck has no .State.Health at all, and the command fails with a template error. The container is fine, the image maker just did not define a check. You can add one yourself with healthcheck: in a Compose file.

Further reading: docker inspect (Docker docs), HEALTHCHECK (Dockerfile reference), On this site: docker logs –since 10m -f shows only what just happened, On this site: make depends_on wait for a healthy database, not just a started one, On this site: Guide: make Docker Compose wait until the database is really ready, not just started

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link