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: the Beszel agent and hub have a health command for Docker healthchecks

Docker
~/tips/tip-beszel-health-command-docker-healthcheck

services:

Lets Docker mark a Beszel container as unhealthy using the built-in health command.

The tool that watches my containers is a container too, so it deserves a healthcheck of its own. Beszel ships the commands for that, for both the agent and the hub.

services:
  beszel-agent:
    healthcheck:
      test: ['CMD', '/agent', 'health']
      interval: 120s

That is the agent example from the Beszel documentation. The agent check verifies that the agent is running properly. It does not prove that the agent is connected to the hub, so a healthy agent can still be a lonely one.

The hub has its own command. It tests whether the /api/health endpoint returns a 200 status code:

services:
  beszel-hub:
    healthcheck:
      test: ['CMD', '/beszel', 'health', '--url', 'http://localhost:8090']
      start_period: 5s
      interval: 120s

The documentation adds a comment on the URL: it is relative to the container, not to the host. Inside the container localhost is the container itself, so the port in that URL has to be one the hub listens on inside the container, which can differ from the port you published on the host.

These checks cost a bit of CPU, and the documentation recommends an interval of 60 seconds or more. A Docker healthcheck only sets a status that you can see in docker ps. It does not send you a message, and it can’t help when the whole machine is down. For that, pair it with the heartbeat setting, which sends pings to an outside service. This follows the documentation and was not run against a live container.

Further reading: Beszel healthchecks

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 (193) All topics

Link