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 ps can list only the containers that fail their health check

Docker
~/tips/tip-docker-ps-filter-unhealthy

docker ps --filter health=unhealthy --format '{{.Names}}'

List unhealthy containers in one line, handy for scripts and alerts.

With twenty containers, the word unhealthy is easy to miss in a long docker ps table. A filter shows only those.

docker ps --filter health=unhealthy --format '{{.Names}}'

The filter accepts starting, healthy, unhealthy and none, the last one for containers without a health check. none is a nice audit too: it shows which containers you have no health information about at all.

Because the output is just names, it fits in a small cron script that only says something when there is a problem:

bad=$(docker ps --filter health=unhealthy --format '{{.Names}}')
[ -n "$bad" ] && echo "Unhealthy: $bad"

Send that line to whatever notifier you use. I like that it needs no extra monitoring tool.

Docker only marks a container unhealthy; it does not restart it. A container can sit in that state for days while the restart policy sees nothing wrong, because the process is still running. And the filter only sees running containers unless you add -a, so one that crashed and stopped shows up in --filter status=exited instead.

Further reading: docker container ls: filtering

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

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