Docker containers
Skirl's Docker companion is a small optional container that watches Docker and sends a message when a container crashes, runs out of memory, fails its health check or keeps restarting, and again when it recovers. Stops, starts and restarts you ask for are not reported unless you turn Activity on.
Docker cannot send a message by itself: something has to watch it. The companion follows Docker's events and sends the ones worth knowing about to a topic, as messages Skirl writes for you. Skirl works the same without it.
Setting it up#
In the app these steps are under Connect a system → Docker, or a topic's Send to this topic tab, with your address, the topic and a token filled in: New token makes the token. Tick the events you want first; the compose file then lists them in EVENTS.
An optional companion container watches Docker’s events and posts the ones worth knowing about: a stop someone asked for, compose down or an update says nothing. It needs nothing else from Skirl.
Access to Docker’s socket is access to the whole host, and mounting it read-only does not change that. The safer form puts a socket proxy in front, which lets the companion read events and containers and refuses everything else. In a folder of its own, put this in compose.yml:
# Skirl's Docker companion (docs/help/docker.md), the safer form: a socket # proxy lets it read events and containers, and refuses everything else. services: socket-proxy: image: docker.io/wollomatic/socket-proxy:1.14.0@sha256:fead157c4de4092461267092be49c993c2e6dd296a54c89ed04b8c870016b045 restart: unless-stopped # The socket is root's; the proxy has no capabilities and a read-only disk. user: "0:0" command: - -listenip=0.0.0.0 - -allowfrom=skirl-docker - '-allowGET=(/v1\.[0-9]+)?/(_ping|version|info|events|containers/json|containers/[a-zA-Z0-9][a-zA-Z0-9_.-]*/json)' volumes: - /var/run/docker.sock:/var/run/docker.sock networks: [docker-proxy] read_only: true cap_drop: [ALL] security_opt: [no-new-privileges:true] skirl-docker: image: ghcr.io/homelabza/skirl-docker:1 restart: unless-stopped depends_on: [socket-proxy] environment: SKIRL_URL: https://notify.example.com/docker SKIRL_TOKEN: tk_replace_with_your_token DOCKER_HOST: tcp://socket-proxy:2375 networks: [docker-proxy, default] # It never watches itself. labels: skirl.notify: "false" read_only: true cap_drop: [ALL] security_opt: [no-new-privileges:true] networks: # Only the companion reaches the proxy, and the proxy reaches nothing. docker-proxy: internal: trueOr the simple form, which gives the companion the socket itself:
# Skirl's Docker companion (docs/help/docker.md), the simple form: it reads # Docker's socket itself. Access to the socket is access to the whole host, # read-only or not; the safer form (compose.safer.yml) puts a proxy in front. services: skirl-docker: image: ghcr.io/homelabza/skirl-docker:1 restart: unless-stopped # The socket is root's: whoever can use it is root on the host. user: "0:0" environment: SKIRL_URL: https://notify.example.com/docker SKIRL_TOKEN: tk_replace_with_your_token volumes: - /var/run/docker.sock:/var/run/docker.sock # It never watches itself. labels: skirl.notify: "false" read_only: true cap_drop: [ALL] security_opt: [no-new-privileges:true]Start it, in that folder:
docker compose up -dCheck it: it reaches Docker and Skirl, sends nothing, and lists what it watches.
docker compose exec skirl-docker /skirl-docker checkSettings: fine Docker: <its version> (API <the version asked for>), on <this host's name> Skirl: https://notify.example.com answers; messages go to the topic docker Events: crash, oom, unhealthy, recovered, restart_loop Watching <n> running containers: <their names> Leaving out 1: <its container> (itself) OKSee a message: a container that crashes at once arrives as "skirl-crash-test crashed":
docker run --rm --name skirl-crash-test busybox:1.37 sh -c 'exit 3'
The same files, with example values, are in the repository as deploy/docker-companion/compose.safer.yml and deploy/docker-companion/compose.yml. The check cannot test the token without sending a message: Skirl checks it on the first one, and the companion's log says so if it is refused.
Events#
The tick boxes come in two groups. Every message names the host, so several hosts can share one topic.
Problems#
On at first, and sent at high priority (4), except Recovered (2).
| Event | On at first | What it means |
|---|---|---|
| Crashed | Yes | A container exited with a code other than 0, and nobody stopped it. The message gives the code and how long it ran. |
| Out of memory | Yes | The kernel killed it for memory. The message gives its memory limit, or says it had none and the host ran short. |
| Unhealthy | Yes | Its health check fails. The message gives the check's last output. |
| Recovered | Yes | It is healthy again, or, after a crash, it has run 10 seconds (or passed its health check, if it has one). This replaces the problem's message, marked resolved, so the topic shows what is wrong now. |
| Restart loop | Yes | It crashed 3 times within 5 minutes. One message, not one per restart, and nothing more until it has run 10 minutes without crashing. |
Activity#
Things you or your tools do on purpose; turn these on for a full record. They are sent at the lowest priority (1): with Notify me from priority set to 2 or more on the topic, they stay in the inbox without a notification (Muting).
| Event | On at first | What it means |
|---|---|---|
| Stopped | No | It stopped: on purpose (a stop, a kill, taking a Compose project down), or by itself with exit code 0. With Restarted on, a stop on purpose waits 30 seconds for a start, and is sent only if none comes. |
| Started | No | It started. With Restarted on, a start within 30 seconds of a stop on purpose is a restart instead. |
| Restarted | No | It was stopped on purpose and started again within 30 seconds: a restart, a Compose restart, a stop followed by a start, or Docker itself restarting. One message, not a stopped and a started. |
| Recreated from a different image | No | It was replaced by a container of the same name from a different image, as Compose does after a pull. Docker cannot say whether the image is newer, only that it changed. One message: not a stop, a start or a restart as well. |
Why a restart you asked for sends nothing#
Everything you or your tools do on purpose is left out unless you turn Activity on: a stop, kill or restart you ask Docker for, taking a Compose project down, an update that recreates a container, and the Docker daemon restarting. Docker sends a kill before each of those, and the companion tells them from a crash by it. So the default topic only ever shows problems.
To see them, tick the Activity events on the sender's page and replace the compose file with the one it shows (its EVENTS line lists them), then start it again in its folder:
docker compose up -dTo keep restarts out of the way of your notifications, send the companion with Activity on to a topic of its own.
The 30 seconds come from what Docker really does: a restart, or a Compose restart, starts the container again within a tenth of a second of its stop; a stop and a start typed by hand were 3 seconds apart; Docker restarting itself started its containers 3 to 13 seconds after stopping them.
What a message looks like#
A crash, at priority 4:
⚠️ 🐳 web crashed · pve01 Exited with code 1 after 2 h 5 min, and nobody stopped it. Image: nginx:1.30-alpine
Priority 4 · Tags: warning, whale
Its recovery replaces it, marked resolved:
✅ 🐳 Resolved: web is running again · pve01 It had crashed, and is running again. Image: nginx:1.30-alpine
Priority 2 · Tags: white_check_mark, whale
A restart, with Activity on:
🔁 🐳 web restarted · pve01 Stopped on purpose and started again within 30 seconds (docker restart, compose restart, or a stop and a start), after running 3 d 4 h. Image: nginx:1.30-alpine
Priority 1 · Tags: repeat, whale
At start the companion says nothing about containers that were already running or already stopped. While Skirl cannot be reached it keeps the last 100 messages and sends them, in order, once Skirl is back. If Docker's event stream ends it connects again and asks for what it missed.
What it sends is the container's name, its image, exit codes, how long it ran, the memory limit and the health check's output. Never its environment, labels or command line.
Safe enough for your server#
Access to Docker's socket is access to the whole host: anything that can use it can start a container as root. Mounting it read-only does not change that, because the socket is an API, not a file. So there are two forms:
- The safer form puts a socket proxy in front. It lets the companion read events and containers (
_ping,version,info,events, the list of containers and one container's details), and refuses everything else: creating a container or running a command in one is refused. Only the companion can reach the proxy, and the proxy reaches nothing. - The simple form gives the companion the socket itself.
Either way the companion only reads. One thing it can read is each container's details, which include its environment; it never sends them anywhere.
Settings#
Everything is set in environment:; nothing is kept on disk.
| Setting | What it is | When it is not set |
|---|---|---|
SKIRL_URL |
the topic's address, such as https://notify.example.com/docker |
required |
SKIRL_TOKEN |
a token that may publish to that topic: New token on its Send to this topic tab | required |
EVENTS |
the events to send, separated by commas: crash, oom, unhealthy, recovered, restart_loop (the Problems), stopped, started, restarted, updated (the Activity) |
the five Problems |
HOST_NAME |
the host's name in every message | Docker's host name |
INCLUDE |
the containers to watch: names or patterns such as web-*, separated by commas |
every container |
EXCLUDE |
the containers to leave out, the same way | none |
DOCKER_HOST |
where Docker is: unix:///var/run/docker.sock, or tcp://socket-proxy:2375 for the proxy |
the socket |
A container labelled skirl.notify=false is always left out, and one labelled skirl.notify=true is watched even if EXCLUDE names it. A setting that is missing or wrong stops the companion at start with one line saying which.
The companion's commands#
The image's command is /skirl-docker; with no argument it runs. Its other commands, run in the folder with the compose file:
docker compose exec skirl-docker /skirl-docker checkThis checks the settings, Docker and Skirl, sends nothing, and ends in OK or a line starting Wrong: that says what to fix.
docker compose exec skirl-docker /skirl-docker versionThis prints its version, which is Skirl's; help in place of version lists the commands.
When nothing arrives#
Run the check above. A line starting
Wrong:names what to fix: a setting, Docker it cannot reach (in the safer form: the proxy is not running, or the companion is not on its network), or Skirl it cannot reach (the address inSKIRL_URL, as seen from the container).Read the companion's log. It says what it sent and what went wrong; "the token was refused" means
SKIRL_TOKENis not a token that may publish to this topic: make a new one with New token.docker compose logs skirl-dockerCrash a container on purpose to see a message arrive. It exits at once and is removed, and arrives as "skirl-crash-test crashed":
docker run --rm --name skirl-crash-test busybox:1.37 sh -c 'exit 3'A stop, a restart or an update sent nothing: that is on purpose; see Why a restart you asked for sends nothing.
One container never reports: it is labelled
skirl.notify=false, left out byINCLUDEorEXCLUDE, or it is the companion itself (it never watches itself).
The rest is as for any sender: A sender gets no message through.
What is known to work#
- Docker Engine 20.10 and later: it speaks the newest API the daemon has, from 1.41 (Docker 20.10) to 1.57 (Docker 29.10). The files above are run for real against Docker 29.10 in CI, with each case in the tables, a restart among them; the companion was also run against Docker Desktop 29.7 on a Mac, where the restarts were recorded.
- Not tested: Docker Desktop on Windows, and rootless Docker (its socket is in the user's runtime directory, not
/var/run). - Not supported: Podman, Swarm and Kubernetes. Podman's Docker-compatible socket may work, untested. On Swarm the companion sees the containers of the node it runs on, not services. Kubernetes does not run containers through Docker.