From d4e5771ab797998195b18586f289054ef0039eca Mon Sep 17 00:00:00 2001 From: Garrett Allen <98648590+Gerrrt@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:17:50 +0000 Subject: [PATCH 1/2] feat(maintenance): prune anonymous volumes no container uses, weekly on prometheus Validation and scratch runs leave anonymous volumes behind: 69 at the 2026-11-13 audit, 99 by 2026-11-23. make prune-images now runs docker volume prune after the image prune. Without --all that removes only com.docker.volume.anonymous volumes, so named volumes survive a stack being down; on an API older than 1.42 the step refuses. Co-Authored-By: Claude Opus 5.5 --- Makefile | 20 +++++++++++++++++--- docs/changelog.md | 15 +++++++++++++++ docs/runbooks/schedule-maintenance.md | 6 ++++-- docs/runbooks/triage-a-critical-alert.md | 3 ++- systemd/homelab-prune-images.service | 8 +++++++- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index c8130c749..22639ac59 100644 --- a/Makefile +++ b/Makefile @@ -501,14 +501,28 @@ port-state: ## Collect whether each container holds the ports and networks it wa $(PYTHON) scripts/collect-port-state.py .PHONY: prune-images -prune-images: ## Remove Docker images no container uses (weekly on the monitoring host) +prune-images: ## Remove Docker images and anonymous volumes no container uses (weekly on the monitoring host) @# The unit says why: nothing else removes superseded digests, and they @# filled `/` once (#136's cutover found it, 2026-09-29). Only images no @# container references, running or stopped. The before and after are @# printed so the journal records what each run reclaimed. - @docker system df --format '{{.Type}}: {{.Size}} ({{.Reclaimable}} reclaimable)' | grep '^Images' + @# + @# Then anonymous volumes no container references. Validation and scratch + @# runs leave them behind: the 2026-11-13 audit found 69, and 99 by + @# 2026-11-23. `docker volume prune` without `--all` removes only volumes + @# carrying `com.docker.volume.anonymous`. It never removes a named volume, + @# so a stack that is down keeps its data. That holds from API 1.42 + @# (Docker 23). On an older daemon it would remove named volumes too, so + @# the step refuses and fails the job instead. + @docker system df --format '{{.Type}}: {{.Size}} ({{.Reclaimable}} reclaimable)' | grep -E '^(Images|Local Volumes)' docker image prune -a -f - @docker system df --format '{{.Type}}: {{.Size}} ({{.Reclaimable}} reclaimable)' | grep '^Images' + @api=$$(docker version --format '{{.Server.APIVersion}}') && \ + if printf '1.42\n%s\n' "$$api" | sort -V -C; then \ + docker volume prune -f; \ + else \ + echo "docker API $$api predates 1.42: volume prune would remove named volumes, refusing" >&2; exit 1; \ + fi + @docker system df --format '{{.Type}}: {{.Size}} ({{.Reclaimable}} reclaimable)' | grep -E '^(Images|Local Volumes)' .PHONY: pkg-state pkg-state: ## Collect package state from morpheus over SSH (FreeBSD, runs as robo) diff --git a/docs/changelog.md b/docs/changelog.md index 4f7a2eedf..65865181a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,21 @@ docstring gives: it is a record, not a claim about now. ## 2026-11-23 +- **The monitoring host's weekly prune also removes anonymous volumes that + no container uses.** The 2026-11-13 audit of `prometheus` found 69 of them, + and there were 99 by today, left behind by validation and scratch runs. + They were pruned by hand today (121.5 MB reclaimed), and the three + `prometheus_` volumes from the 2025 compose project were removed with them. + `make prune-images` now runs `docker volume prune` after the image prune. + Without `--all`, that removes only volumes labelled + `com.docker.volume.anonymous`, so a named volume survives even while its + stack is down. A probe on the host proved it both ways: a dangling + anonymous volume went, and a dangling named one stayed. On a Docker API + older than 1.42, where prune would also take named volumes, the step + refuses and the job fails. The agent hosts' copy is unchanged. The unit's + description changed, so the next `sudo make install-timers` on + `prometheus` is what brings the installed unit back in line. + - **`prometheus` will take SSH keys only, and stays without a host firewall ([ADR-0128](adr/0128-give-prometheus-a-key-only-sshd-and-no-host-firewall.md)).** The root-only reads that finished the 2026-11-13 audit were taken today. diff --git a/docs/runbooks/schedule-maintenance.md b/docs/runbooks/schedule-maintenance.md index bd4ba8f45..64b420d4d 100644 --- a/docs/runbooks/schedule-maintenance.md +++ b/docs/runbooks/schedule-maintenance.md @@ -206,7 +206,9 @@ disabling the first proves the second, which is so they install on the hypervisor and nowhere else. **`prune-images` is the agent hosts' copy of the `prune-images` row above.** It -runs `docker image prune -a` on Mondays at 04:00, as the monitoring host's does, +runs `docker image prune -a` on Mondays at 04:00, as the monitoring host's does. +Unlike the monitoring host's, it leaves anonymous volumes alone. Those come from +`make validate` and scratch runs, which happen on the monitoring host. It runs from `systemd/agent/homelab-prune-images.timer`. Nothing removed superseded images on an agent host before it, and on 2026-10-01 `odin`'s 30 GB root was at 98%, 7.8 GB of it images no container used. It requires `/usr/bin/docker`, so @@ -943,7 +945,7 @@ expected rather than a second fault. | `smart-state-remote` exits 1 | `morpheus` could not be read over SSH | The warning line carries ssh's own message — `Permission denied (publickey)` means the key or the user is wrong, `No route to host` means the firewall is unreachable. This job runs as `robo` and uses the same key as `backup-firewall`, so if that job is also failing the cause is shared | | `pkg-state` exits 1 | `morpheus` could not be read, or its catalogue fetch failed | The message carries ssh's or pkg's own words. A catalogue fetch needs the firewall to reach its update servers, so a WAN outage looks exactly like this and is not a fault in the collector — check `BlackboxProbeFailed` for the gateway before investigating. It runs as `robo` with the same key as `backup-firewall`, so if that is failing too the cause is shared | | `silence-state` exits 1 | Alertmanager could not be read on loopback, or answered something that is not a silence list | The previous `alertmanager-silences.prom` is left in place, so the last known silences stay served and a silence deleted during the outage looks alive until the next successful run — by design, because an empty file would read as "no silences". `docker ps` for the container, then `make silence-state` by hand | -| `prune-images` exits non-zero | `docker image prune` failed, or the `backups` lock was held for the whole 900s wait | The journal line says which. A lock timeout means a backup or converge ran long, and the next week's run catches up. Anything else, run `make prune-images` by hand and read Docker's error. Until it runs, unused images accumulate at a few gigabytes a week, and `HostDiskWillFillIn24h` and `HostDiskCritical` are the backstop | +| `prune-images` exits non-zero | `docker image prune` or `docker volume prune` failed, the Docker API is older than 1.42 (the job refuses to prune volumes there, because an older daemon would remove named ones too), or the `backups` lock was held for the whole 900s wait | The journal line says which. A lock timeout means a backup or converge ran long, and the next week's run catches up. Anything else, run `make prune-images` by hand and read Docker's error. Until it runs, unused images accumulate at a few gigabytes a week, and `HostDiskWillFillIn24h` and `HostDiskCritical` are the backstop | | `check-versions` exits 1 | A document names an OS version the host is not running | Not an outage — nothing is broken. Read the FAIL lines: each names the document, the cell and what the host reports. Correct the document; the box is the source of truth. A `SKIP` for `morpheus` instead means `sysDescr` is not reaching Prometheus, which is a collection fault rather than a clean bill of health | | `docker info` fails only under systemd | The unit is missing `SupplementaryGroups=docker` | A login shell picks the group up from `/etc/group` and a unit does not, which is why this never reproduces by hand | | Timers exist but never fire | `WantedBy=timers.target` missing, or the timers were never enabled | `systemctl list-timers 'homelab-*'` shows nothing; re-run `make install-timers` | diff --git a/docs/runbooks/triage-a-critical-alert.md b/docs/runbooks/triage-a-critical-alert.md index fbd8be507..0ab9ae238 100644 --- a/docs/runbooks/triage-a-critical-alert.md +++ b/docs/runbooks/triage-a-critical-alert.md @@ -110,7 +110,8 @@ A filesystem has less than 10% free. - **Find what is growing:** `du -xh --max-depth=1 | sort -h` on the host. On a Docker host, `docker system df` first: superseded images - are the usual cause. + are the usual cause, and on the monitoring host, anonymous volumes left by + validation runs are the next. - **The monitoring host:** Prometheus's retention is capped by size (`PROMETHEUS_RETENTION_SIZE`), so it should not be Prometheus. Loki's chunks and the backup staging directory are the usual suspects. diff --git a/systemd/homelab-prune-images.service b/systemd/homelab-prune-images.service index 69ebc6ca8..e5e2d82ff 100644 --- a/systemd/homelab-prune-images.service +++ b/systemd/homelab-prune-images.service @@ -15,12 +15,18 @@ # what was pulled this week". An image removed here that `make validate` wants # again is re-pulled only on a proof-cache miss, which a new digest is anyway. # +# Since 2026-11-23 it also removes anonymous volumes no container references +# (`docker volume prune`, never `--all`). Validation and scratch runs leave +# them behind: 99 had built up by then. Named volumes, which hold every +# stack's data, are never touched, even while a stack is down. The Makefile +# target says how it refuses on a daemon too old to tell the two apart. +# # Under the `backups` lock that converge and the backups share, so a prune can # never land between a converge's pull and its `compose up`. # # See homelab-backup-volumes.service for why each directive below is set. [Unit] -Description=HomeLab: remove Docker images no container uses +Description=HomeLab: remove Docker images and anonymous volumes no container uses Documentation=file:///home/robo/code/Gerrrt/HomeLab/docs/runbooks/schedule-maintenance.md After=docker.service From 37ac115790f3cd76e3193f14a61521ba688e3a30 Mon Sep 17 00:00:00 2001 From: Garrett Allen <98648590+Gerrrt@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:25:51 +0000 Subject: [PATCH 2/2] fix(maintenance): filter volume prune to the anonymous label, not an API check The daemon's API version does not bound the request's: an old client or DOCKER_API_VERSION=1.41 still sends a pre-1.42 prune, which takes named volumes. Filter on com.docker.volume.anonymous instead; an API 1.41 request with the filter kept a dangling named volume on prometheus. Co-Authored-By: Claude Opus 5.5 --- Makefile | 19 ++++++++----------- docs/changelog.md | 15 ++++++++------- docs/runbooks/schedule-maintenance.md | 2 +- systemd/homelab-prune-images.service | 8 ++++---- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 22639ac59..7385d9b62 100644 --- a/Makefile +++ b/Makefile @@ -509,19 +509,16 @@ prune-images: ## Remove Docker images and anonymous volumes no container uses (w @# @# Then anonymous volumes no container references. Validation and scratch @# runs leave them behind: the 2026-11-13 audit found 69, and 99 by - @# 2026-11-23. `docker volume prune` without `--all` removes only volumes - @# carrying `com.docker.volume.anonymous`. It never removes a named volume, - @# so a stack that is down keeps its data. That holds from API 1.42 - @# (Docker 23). On an older daemon it would remove named volumes too, so - @# the step refuses and fails the job instead. + @# 2026-11-23. The filter selects only volumes carrying + @# `com.docker.volume.anonymous`, so a named volume is never removed and a + @# stack that is down keeps its data. The filter is explicit on purpose: + @# prune's own default of anonymous-only depends on the request's API + @# version, and a request below 1.42 (an old client, or + @# DOCKER_API_VERSION) prunes named volumes too. Proved on prometheus: an + @# API 1.41 request with this filter kept a dangling named volume. @docker system df --format '{{.Type}}: {{.Size}} ({{.Reclaimable}} reclaimable)' | grep -E '^(Images|Local Volumes)' docker image prune -a -f - @api=$$(docker version --format '{{.Server.APIVersion}}') && \ - if printf '1.42\n%s\n' "$$api" | sort -V -C; then \ - docker volume prune -f; \ - else \ - echo "docker API $$api predates 1.42: volume prune would remove named volumes, refusing" >&2; exit 1; \ - fi + docker volume prune -f --filter label=com.docker.volume.anonymous @docker system df --format '{{.Type}}: {{.Size}} ({{.Reclaimable}} reclaimable)' | grep -E '^(Images|Local Volumes)' .PHONY: pkg-state diff --git a/docs/changelog.md b/docs/changelog.md index 476c7f036..8d7f4dd91 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -24,13 +24,14 @@ docstring gives: it is a record, not a claim about now. and there were 99 by today, left behind by validation and scratch runs. They were pruned by hand today (121.5 MB reclaimed), and the three `prometheus_` volumes from the 2025 compose project were removed with them. - `make prune-images` now runs `docker volume prune` after the image prune. - Without `--all`, that removes only volumes labelled - `com.docker.volume.anonymous`, so a named volume survives even while its - stack is down. A probe on the host proved it both ways: a dangling - anonymous volume went, and a dangling named one stayed. On a Docker API - older than 1.42, where prune would also take named volumes, the step - refuses and the job fails. The agent hosts' copy is unchanged. The unit's + `make prune-images` now runs `docker volume prune` after the image prune, + filtered to volumes labelled `com.docker.volume.anonymous`, so a named + volume survives even while its stack is down. The filter is explicit + because prune's own anonymous-only default depends on the request's API + version, and a request below 1.42 takes named volumes too. A probe on the + host proved it both ways, including with `DOCKER_API_VERSION=1.41`: a + dangling anonymous volume went, and a dangling named one stayed. The + agent hosts' copy is unchanged. The unit's description changed, so the next `sudo make install-timers` on `prometheus` is what brings the installed unit back in line. diff --git a/docs/runbooks/schedule-maintenance.md b/docs/runbooks/schedule-maintenance.md index 64b420d4d..8fb3104bd 100644 --- a/docs/runbooks/schedule-maintenance.md +++ b/docs/runbooks/schedule-maintenance.md @@ -945,7 +945,7 @@ expected rather than a second fault. | `smart-state-remote` exits 1 | `morpheus` could not be read over SSH | The warning line carries ssh's own message — `Permission denied (publickey)` means the key or the user is wrong, `No route to host` means the firewall is unreachable. This job runs as `robo` and uses the same key as `backup-firewall`, so if that job is also failing the cause is shared | | `pkg-state` exits 1 | `morpheus` could not be read, or its catalogue fetch failed | The message carries ssh's or pkg's own words. A catalogue fetch needs the firewall to reach its update servers, so a WAN outage looks exactly like this and is not a fault in the collector — check `BlackboxProbeFailed` for the gateway before investigating. It runs as `robo` with the same key as `backup-firewall`, so if that is failing too the cause is shared | | `silence-state` exits 1 | Alertmanager could not be read on loopback, or answered something that is not a silence list | The previous `alertmanager-silences.prom` is left in place, so the last known silences stay served and a silence deleted during the outage looks alive until the next successful run — by design, because an empty file would read as "no silences". `docker ps` for the container, then `make silence-state` by hand | -| `prune-images` exits non-zero | `docker image prune` or `docker volume prune` failed, the Docker API is older than 1.42 (the job refuses to prune volumes there, because an older daemon would remove named ones too), or the `backups` lock was held for the whole 900s wait | The journal line says which. A lock timeout means a backup or converge ran long, and the next week's run catches up. Anything else, run `make prune-images` by hand and read Docker's error. Until it runs, unused images accumulate at a few gigabytes a week, and `HostDiskWillFillIn24h` and `HostDiskCritical` are the backstop | +| `prune-images` exits non-zero | `docker image prune` or `docker volume prune` failed, or the `backups` lock was held for the whole 900s wait | The journal line says which. A lock timeout means a backup or converge ran long, and the next week's run catches up. Anything else, run `make prune-images` by hand and read Docker's error. Until it runs, unused images accumulate at a few gigabytes a week, and `HostDiskWillFillIn24h` and `HostDiskCritical` are the backstop | | `check-versions` exits 1 | A document names an OS version the host is not running | Not an outage — nothing is broken. Read the FAIL lines: each names the document, the cell and what the host reports. Correct the document; the box is the source of truth. A `SKIP` for `morpheus` instead means `sysDescr` is not reaching Prometheus, which is a collection fault rather than a clean bill of health | | `docker info` fails only under systemd | The unit is missing `SupplementaryGroups=docker` | A login shell picks the group up from `/etc/group` and a unit does not, which is why this never reproduces by hand | | Timers exist but never fire | `WantedBy=timers.target` missing, or the timers were never enabled | `systemctl list-timers 'homelab-*'` shows nothing; re-run `make install-timers` | diff --git a/systemd/homelab-prune-images.service b/systemd/homelab-prune-images.service index e5e2d82ff..887bbd540 100644 --- a/systemd/homelab-prune-images.service +++ b/systemd/homelab-prune-images.service @@ -16,10 +16,10 @@ # again is re-pulled only on a proof-cache miss, which a new digest is anyway. # # Since 2026-11-23 it also removes anonymous volumes no container references -# (`docker volume prune`, never `--all`). Validation and scratch runs leave -# them behind: 99 had built up by then. Named volumes, which hold every -# stack's data, are never touched, even while a stack is down. The Makefile -# target says how it refuses on a daemon too old to tell the two apart. +# (`docker volume prune` filtered to `com.docker.volume.anonymous`). +# Validation and scratch runs leave them behind: 99 had built up by then. +# Named volumes, which hold every stack's data, are never touched, even +# while a stack is down. The Makefile target says why the filter is explicit. # # Under the `backups` lock that converge and the backups share, so a prune can # never land between a converge's pull and its `compose up`.