360 Secure SkillHub
360 安全技能中心

Docker Health Monitor

该 Skill 通过 bash 脚本调用 Docker CLI,检查容器运行状态、CPU/内存使用、重启次数以及镜像更新可用性,并输出格式化健康报告。支持单项检查或完整审计,需要访问 Docker socket,镜像更新检查需网络访问镜像仓库。

laolaoqi
laolaoqi
热度 25.14
最近更新 2026-05-12 07:08:17
分类:开发依赖:代码执行 / 第三方 API应用场景:DevOps / 报告撰写 / 自动化脚本 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add laolaoqi-docker-health
Metadata
name
docker-health-monitor
description
Monitor Docker container health: running status, CPU/memory usage, restart counts, and available image updates. Use when a user requests Docker health checks, container monitoring, resource usage reports, restart tracking, or image freshness audits — run targeted checks or a full health report.

Docker Health Monitor

Script

scripts/docker-health.sh — the single entry point for all checks.

The script is self-contained and works on any system with Docker installed. It auto-detects the Docker socket availability and gracefully handles permission issues.

Quick Start

Run a full health report:

bash scripts/docker-health.sh --all

Or with no arguments (same as --all):

bash scripts/docker-health.sh

Individual Checks

Run any single check by name:

Command What it checks
--status Lists all containers with their current status (running, stopped, paused, etc.)
--resources Shows CPU and memory usage per container via docker stats
--restarts Flags containers that have restarted more than 3 times
--images Checks for available image updates by comparing local image digests with registry
--full Runs all checks in sequence (same as --all)

Example:

bash scripts/docker-health.sh --status --restarts

Full Audit Workflow

  1. Run bash scripts/docker-health.sh --all
  2. The script outputs a formatted report to stdout
  3. Key sections: container status summary, resource usage table, restart warnings, image update availability

Common Findings & Recommendations

  • High restart counts (>3): Indicates container instability — check logs with docker logs <container> and review healthcheck configuration
  • High memory usage: Consider setting --memory limits in the container's run/stack config; check for memory leaks in the application
  • High CPU usage: Investigate application processes; consider CPU limits or horizontal scaling
  • Outdated images: Run docker pull to update images; consider automated update workflows (watchtower, renovate-bot)
  • Exited containers: Check exit codes — 0 means intentional stop, non-zero indicates errors

Notes

  • Requires access to the Docker socket (/var/run/docker.sock) — run as root or add user to the docker group
  • --resources runs docker stats in non-streaming mode (one-shot per container) for quick snapshots
  • --images checks are advisory — uses docker inspect for image digests and checks for newer versions; requires network access to the registry
  • Works with both local Docker and remote Docker contexts (DOCKER_HOST env var)