Manage Docker containers: status reports, log analysis, and restarts via docker-socket-proxy.
docker CLI available in PATHjq available in PATHDOCKER_HOST environment variable is pre-configured (do NOT override it manually)whitelist.yml in the agent workspace rootBefore any Docker command, check the SYSCTL_WHITELIST_PATH environment variable.
If SYSCTL_WHITELIST_PATH is NOT set or empty:
SYSCTL_WHITELIST_PATH is not configured. Set this environment variable in the container to point to the whitelist YAML file."If set, read the whitelist file from that path. There is no fallback file.
Structure:
yaml
containers:
- name: container_name
description: "Human description"
can_restart: true|false
Rules:
can_restart: false<name> is not in the whitelist. Available: "You may ONLY use these Docker commands:
CommandWhendocker ps --format jsonList running containersdocker ps -a --format jsonList all containers (including stopped)docker inspect <name>Get container details (status, uptime, restart count)docker stats --no-stream --format json <name>Get resource usage (CPU, RAM, NET, BLOCK)docker logs --since <period> --tail 500 <name>Read container logsdocker restart <name>Restart a container (explicit request only!)
NEVER execute: docker rm, docker stop, docker kill, docker exec, docker run, docker pull, docker build, docker push, docker network, docker volume, docker image, docker system, docker compose.
When asked for a status report:
Convert user text to --since parameter:
1h24h30m168h1h168h (7 days). If user requests more — cap at 168h and inform them.All docker commands must be wrapped with timeout 30 to prevent hanging.
bash
# Status + uptime + restart count
timeout 30 docker inspect <name> | jq '.[0] | {Status: .State.Status, StartedAt: .State.StartedAt, RestartCount: .RestartCount, Health: .State.Health.Status}'
# Resource usage
timeout 30 docker stats --no-stream --format '{{json .}}' <name>
# Fetch logs once, then count errors and warnings locally
LOG_OUTPUT=$(timeout 30 docker logs --since <period> --tail 5000 <name> 2>&1)
# Error/warning count (quick stats)
echo "${LOG_OUTPUT}" | grep -ci 'error\|exception\|fatal\|traceback'
echo "${LOG_OUTPUT}" | grep -ci 'warn'
# Last errors (up to 10 unique)
echo "${LOG_OUTPUT}" | grep -i 'error\|exception\|fatal\|traceback' | sort -u | tail -10
Before displaying log fragments to users, mask sensitive patterns:
Replace with [REDACTED] where detected.
Use this template (adapt to language of request):
text
<status_emoji> **<container_name>**
**Status:** `running` (uptime: 2d 5h 13m)
**Restarts:** 0
**CPU:** 2.3% | **RAM:** 145MiB / 512MiB (28%)
**NET I/O:** 1.2MB / 340KB | **BLOCK I/O:** 12MB / 5MB
**Logs at last hour:**
- 🔴 Errors: 3
- ⚠️ Warnings: 12
**Last errors:**
• `ConnectionRefusedError: connect to postgres:5432`
• `TimeoutError: request took >30s`
**Recommendation:** Check access to PostgreSQL
Status emoji rules:
When asked to restart a container:
Verify container is in whitelist AND can_restart: true
Confirm the request is explicit (user said "restart", "перезапусти", "рестартни")
Cooldown check: do not restart the same container more than once per 5 minutes. If repeated — warn and ask to confirm.
Audit log: before executing, output: text
[AUDIT] <ISO-timestamp> restart <container_name> requested_by=<user_id_if_available>
Execute: timeout 30 docker restart <name>
Wait and verify with retries: bash
for i in 1 2 3; do
sleep 10
STATUS=$(timeout 30 docker inspect <name> | jq -r '.[0].State.Status')
if [ "${STATUS}" = "running" ]; then break; fi
done
If running → report success with new status
If not running after 30s → report failure with last 20 log lines:
timeout 30 docker logs --tail 20 <name> 2>&1
When asked to show logs:
--tail 500 limit alwaysgrep2>&1 when piping docker logs (stderr contains the actual logs)DOCKER_HOST is not set, do NOT guess the address — report to user: "DOCKER_HOST is not configured. Set this environment variable to point to the docker-socket-proxy endpoint."