feat: opt-in /api/containers listing running Docker containers and their uptime

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan GroßandClaude Sonnet 5.5 committed 2026-11-17 12:35:45 +01:00
1 parent 0c9dd7c9b3
commit 10aaa13aeb
3 files changed
+148 -2

No files matched your search

+22
View File
@@ -54,6 +54,26 @@ If `/host/proc` isn't mounted at all, `/api/stats` still returns data, just
for the container's own near-empty cgroup instead of the host —
`network.hostNamespace` in the response tells you which one you're getting.
## Containers (optional)
`GET /api/containers` lists the running Docker containers (name, image, health,
restart count, uptime) for the dashboard's Containers block. It is **off by
default**, because reaching the Docker API is a much bigger privilege than the
read-only host mounts above. Pick one:
- **Socket proxy (recommended).** Run a read-only proxy such as
`tecnativa/docker-socket-proxy` with only `CONTAINERS=1` enabled, and point the
agent at it with `DOCKER_HOST=tcp://socket-proxy:2375`. The proxy is the only
thing that touches the socket, and it refuses everything but container reads.
- **Mount the socket.** `-v /var/run/docker.sock:/var/run/docker.sock:ro` plus
`--group-add <the host's docker group id>` (the agent runs as a non-root
user). Note that even a `:ro` socket mount gives full control of Docker to
anything that can talk to it, so anyone who gets the agent's API key and a bug
to exploit is effectively root on the host.
Without either, the endpoint answers 503 and everything else works as before.
Only names, images, state and start times are ever returned.
## API
Every endpoint except `/api/health` requires an `X-API-Key` header.
@@ -62,6 +82,7 @@ Every endpoint except `/api/health` requires an `X-API-Key` header.
|--------|------|---------|
| GET | `/api/health` | Liveness check, no auth — used by the Docker `HEALTHCHECK` |
| GET | `/api/stats` | A snapshot of CPU/memory/disk/network for the host |
| GET | `/api/containers` | Running Docker containers and their uptime (opt-in, see above) |
`GET /api/stats` response shape:
@@ -110,4 +131,5 @@ curl -H "X-API-Key: $API_KEY" http://localhost:9090/api/stats
|----------|---------|---------|
| `API_KEY` | auto-generated on first run | The key clients must send as `X-API-Key` |
| `AGENT_DATA_DIR` | `/data` | Where the auto-generated key is persisted |
| `DOCKER_HOST` | `unix:///var/run/docker.sock` | Where to reach the Docker API for `/api/containers` (`tcp://host:port` for a socket proxy) |
| `AGENT_HOSTNAME` | host's `/etc/hostname`, or the container's | Overrides the reported `hostname` |