Margrop
Articles380
Tags807
Categories7

Categories

/health 200 /v1/models 0.025s 0步 0步主动 0步元递归 0步本身 12类 18789 18天idle 18天静默 192.168.x.x 1password 22类一键汇总 3层定位法 401 4个Gateway 4个Gateway全军覆没 4步主动 4步定位 503 5步定位法 60秒延迟 60秒超时 6个节点 AC ACP AI AI Coding Assistant AI编程助手 AI辅助 AI辅助编程 AP API Agent couldn't generate Alertmanager AppDaemon Aqara BaiduPCS CC-Switch CI/CD CLI Tools CLI工具 CONFIG Caddy Chrome缺失 Claude Code Cloudflare Codex Cookie 认证 Cron D1 DB探针 DB静止 DIY-123模型 DIY-MINI DIY平台 Date Diagrams.net Diary Docker Docker Compose EADDRINUSE EasyTier NAT穿透 Efficiency Tools Electerm English FTS5 Gateway Gemini CLI GitHub Actions HA HADashboard Hermes Hexo HomeAssistant IP IPv4 Java LVM‑Thin Linux MacOS Macmini Macmini log路径 Markdown MiniMax MiniMax-M3 Multi-Agent MySQL NAS NRestarts Nginx Node-RED Node.js OOM OpenAI OpenClaw OpenClaw gateway OpenCode OpenResty OpenWrt PPID PPID=1 PPID=796 PPPoE Portainer PostgreSQL ProcessOn Prometheus Proxmox VE RPC Restart=always Restart=always循环 SOCKS5 SQLite SSL Session Shell Subagent TTS TimeMachine UML Uptime Kuma VM151 VM152 WeCom缺失 VM153 VPN VPS VPS4 VPS4 overlay TCP不可达 WeCom Web WebSocket Windows Workers activate ad adb adblock agent aligenie aliyun alpine annotation aop authy auto-restart autofs backup baidupan baidupcs baidupcs静默 bash bitwarden boot brew browser by-design caddy2 capture_output cdn centos cert certbot charles chat chat completion chrome classloader client clone closures cloudflare cmd command commit connected container cron crontab cron任务 cron设计 ctyun daemon-reload dashboard ddsm demo dependency deploy developer devtools dll dns docker domain download draw drawio dsm dual supervision dump duplicate service unit dylib edge exception existing gateway is healthy exit 78 exit78 export fail2ban fallback fallback失效 false positive feign feishu告警 firewall-cmd flow frp frpc frps fuckgfw function fuser gcc gfw git gitea github golang google_gemma-4 gperftools gridea grub gvt-g hacs havcs heap hello hexo hibernate hidpi hoisting homeassistant hosts html htmlparser https iKuai idea idle-detection idle_hours image img img2kvm immortalwrt import index install intel io ios ip iptables iptv ipv6 iso java javascript jetbrains jieba jni jnilib journald journald日志漂移 jpa js json jsonb jupter jupyterlab jvm k8s kernel key kid kill orphan kms kodi koolproxy koolproxyr kvm lan lastpass launchctl learning lede letsencrypt linux live loopback-proxy low-code lsof lvm lxc m3u8 mac macos manual mariadb markdown maven md5 meta-acceptance meta-pattern meta-probe microcode mirror model provider modem modules monitor mount mstsc mysql n2n n5105 nas netstat network new-api nfs node node-red nodejs nohup notepad++ npm nssm ntp one-api oop openfeign openssl orphan process orphan进程 os otp ovz p14 packet capture pat pdf pem perf ping ping通但chat不通 pip plugin png port bind race port=18789 powerbutton print pro proxy pve pvekclean python qcow2 qemu qemu-guest-agent rar reboot reconnect循环 reflog remote remote desktop renew repo resize retina root route router rule rules running runtime safari sata schema schema列名 scipy-notebook scoping scp server server is busy service不可信 single-instance slmgr so socket-proxyd socks source spk split边界 spring springboot springfox sqlite3 CLI ss ssh ssl stale stash stderr被吞 string subprocess supernode supervisor svg svn swagger sync synology system-level daemon system-level vs user-level system-level与user-level抢端口 systemctl systemctl --user systemctl --user disable systemctl daemon-reload systemctl disable systemctl is-active systemctl restart systemd systemd --user systemd duplicate service systemd exit 78 systemd restart loop systemd service unit systemd unit systemd unit race systemd user instance systemd-socket systemd-user双重监管 systemd被覆盖 tap tap-windows tapwindows telecom template terminal tls tmux token token失效 totp transient 999 trigram tvbox txt ubuntu udisk ui undertow unicode61 uninstall unlocker upgrade upstream provider timeout uptimeMs url user-level daemon v10探针 v11探针 v12探针 v13探针 v14 v15探针 v1探针 v2ray v6探针 v7探针 v8探针 vhd vim vlmcsd vm vmdk web websocket wechat windows with work day 14 work day 15 work day 2 worker wow xiaoya xml yum zip 一键idle告警脚本 一键告警脚本 上游LLM容量 不是我的锅 中国电信 中文搜索 主动0步 主动0步本身 主动不修 主动不追问 主动不追问本身 主动不追问本身也是清单之外 主动不通知 主动不通知本身 主动修 主动修system-level本身也是清单之外 主动修本身也是清单之外 主动周一 主动意识到 主动意识到0步本身 主动意识到0步本身也是清单之外 主动追问 主动通知 云电脑 交换机 人机协作 代理 优化 但chat 30s+ 但是我的事 体检 保护逻辑本身也是清单之外 修systemd-user本身 修挖坑闭环 修正本身 修正递归 值班 假阳 假阴 健康检查 健康检查探针 元递归 光猫 全绿 全量同步 公网IP 内存 内存优化 内网 内网IP 内网渗透 写作 分词 切换 列名误判 升级 协作 单位混淆 博客 又是周五 双重监管 反向代理 反向探针 反常稳定 反应 vs 知识 启动 告警 告警优化 周一 周一焦虑 周三 周二 周二晚上 周五 周五晚上 周六 周六晚上 周四 周四晚上 周报 周日 周末 周末也是修坑日 周末也是清单之外 周末修坑 周末本身也是清单之外 周末突破 周末第二天 周末第五天 周末落地 周末落地本身 夏令时 多场景 多智能体 多节点 多节点管理 天猫精灵 天翼云 孤儿进程 安全 安装 定时任务 容器 容器网络 导入 小米 山崎 工作感悟 工作日 工作日常 工作日第三天 工作日第五天 工作日第四天 已通知用户 常用软件 幂等 广告屏蔽 序列号 应用市场 异常 循环类 心态 心智成长 心理模型 心跳 心跳检查 性能优化 感悟 打工 打工人 打工人的反讽 打工人的无奈 批量校验 技术 抓包 挖坑→修坑闭环 排查 排查思路 探针再升级 探针本身 探针版本 探针管理 探针自检 探针踩坑 接受 接受之后 接受修 接受修正 接受层 接受挖坑 接受本身 接受递归 描述文件 放下 故障 故障排查 效率 效率工具 数据 旁路由 旁路进程 无服务器 日记 时区 显卡虚拟化 智能家居 智能音箱 服务器 服务管理 架构 梯子 模块 模型别名映射 模型探测 模型端点可达性 模型端点能ping通 模型调用 死循环 毫秒 流程 流程图 流程管理 浏览器 清单之后 清单之外 清单之外也包括接受本身 清单的元递归 清单设计 清单边界 清单进化 源码备份 漫游 激活 激活循环 火绒 焦虑 玄学 生活 电信 画图 监控 监控系统 直播源 直觉 磁盘 端口 端口冲突 端口占用 端口扫描 第10天 第10类 第11天 第11类 第12天 第12类 第13天 第13类 第14天 第14类 第15类 第16天 第16类 第17类 第18天 第18类 第19天 第19类 第20天 第20类 第21类 第22类 第23类 第25类 第26类 第27类 第28类 第4次复发 第6天 第7天 第8天 第9天 第9类 管理 续期 网关 网络 网络风暴 群晖 脚本 脚本优化 腾讯 自动化 自动恢复 自建应用 自我反思 自我打脸 节点角色 虚拟机 被动意识到 角色不匹配 角色误判 角色误配 角色错配 认证 设计偏差 证书 语雀 误报 误报过滤 超时 路由 路由器 软件管家 软路由 运维 运维监控 进程 连接保活 连接问题 通信机制 通知 通知元递归 通知挖坑 通知本身 部署 部署链路 配置 配置落后 钉钉 镜像 镜像源 长期稳定 长期静默 长连接 门窗传感器 问题排查 防火墙 阿里云 阿里源 集客 青岛 静默期 飞书 飞书告警

Hitokoto

Archive

Docker容器健康检查与自愈机制实战:从检测到恢复的完整方案

Docker容器健康检查与自愈机制实战:从检测到恢复的完整方案

前言

容器化部署已经成为现代运维的标配,但在实际生产环境中,容器可能会因为各种原因退出、卡死或者无法正常提供服务。单纯依靠 Docker 的默认重启策略往往不够,我们需要一套完整的健康检查与自愈机制来保障服务的稳定性。本文将详细介绍如何在 Docker 容器中实现健康检查、故障检测和自动恢复的完整方案。

为什么需要容器健康检查

Docker 默认重启策略的局限

Docker 提供了 --restart 参数来配置容器重启策略:

1
2
3
4
5
6
7
8
# always 策略:容器退出后总是重启
docker run --restart always my-image

# on-failure 策略:非零退出码时重启,最多重启5次
docker run --restart on-failure:5 my-image

# unless-stopped 策略:除了手动停止外,总是重启
docker run --restart unless-stopped my-image

这些策略的局限性在于:

策略 能检测的问题 无法检测的问题
always 进程崩溃退出 进程卡死、假死
on-failure 非零退出 进程假死、响应超时
unless-stopped 进程崩溃退出 所有运行时异常

举几个例子:

  • 进程假死:进程还在运行,但已经不响应任何请求。Docker 只会看到进程存在,不会主动杀死它。
  • 死锁:应用程序内部死锁,线程全部阻塞,但主进程存活。
  • 资源耗尽:容器进程耗尽内存或文件描述符,但没达到 OOM 阈值。
  • 响应超时:服务还在跑,但响应时间从 10ms 变成了 30s。

这些都是 Docker 默认策略检测不到的,也是我们需要额外健康检查的原因。

健康检查的价值

一个好的健康检查机制可以实现:

  1. 及时发现问题:在用户发现之前就检测到问题
  2. 自动恢复:无需人工介入,自动重启问题容器
  3. 减少停机时间:快速恢复比人工响应快得多
  4. 可观测性:通过健康检查日志了解服务状态变化

Docker HEALTHCHECK 指令详解

基本语法

Docker 提供了 HEALTHCHECK 指令来定义容器的健康检查机制:

1
2
HEALTHCHECK [--interval=5m] [--timeout=3s] [--retries=3] [--start-period=30s] \
COMMAND

参数说明:

参数 默认值 说明
–interval 30s 检查间隔
–timeout 30s 单次检查超时时间
–retries 3 连续失败次数达到此值视为不健康
–start-period 0s 容器启动后的等待期,期间不计入健康状态

实用示例

示例一:Web 服务健康检查

1
2
3
4
5
6
7
FROM nginx:alpine

# 30秒检查一次,超时3秒,连续3次失败视为不健康
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -f http://localhost:80/health || exit 1

EXPOSE 80

其中 health 端点可以是:

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 80;
server_name _;

location /health {
access_log off;
return 200 "OK\n";
}

location / {
# 实际业务配置
}
}

示例二:API 服务健康检查

1
2
3
4
5
6
7
8
9
10
FROM python:3.11-slim

WORKDIR /app
COPY . .

# 检查多个依赖项:数据库、Redis、外部API
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=40s \
CMD python3 /app/healthcheck.py

EXPOSE 8000

对应的 healthcheck.py:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import sys
import requests

def check_health():
checks = []

# 检查主服务
try:
r = requests.get("http://localhost:8000/health", timeout=2)
if r.status_code == 200:
checks.append(("main_service", True))
else:
checks.append(("main_service", False))
except Exception as e:
checks.append(("main_service", False))

# 检查数据库连接
try:
from app.database import db
db.execute("SELECT 1")
checks.append(("database", True))
except Exception as e:
checks.append(("database", False))

# 检查 Redis
try:
import redis
r = redis.Redis(host='localhost', port=6379, socket_timeout=2)
r.ping()
checks.append(("redis", True))
except Exception as e:
checks.append(("redis", False))

# 任意一项检查失败,整个健康检查失败
for name, ok in checks:
if not ok:
print(f"Health check failed: {name}")
sys.exit(1)

print("All checks passed")
sys.exit(0)

if __name__ == "__main__":
check_health()

示例三:多协议健康检查

1
2
3
4
5
6
7
8
9
10
11
# TCP 端口检查
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD nc -z localhost 5432 || exit 1

# HTTPS 健康检查(带证书验证)
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider https://localhost:443/health || exit 1

# gRPC 健康检查
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD grpcurl -plaintext localhost:50051 grpc.health.v1.Health/Check || exit 1

Docker Compose 中的健康检查配置

完整配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
version: '3.8'

services:
web:
image: nginx:alpine
ports:
- "80:80"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 40s
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3

api:
image: my-api:latest
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "python3", "/app/healthcheck.py"]
interval: 30s
timeout: 5s
retries: 3
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
restart_policy:
condition: on-failure

db:
image: postgres:15-alpine
environment:
POSTGRES_PASSWORD: secret
volumes:
- db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
deploy:
restart_policy:
condition: on-failure

redis:
image: redis:7-alpine
command: redis-server --appendonly yes
volumes:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
deploy:
restart_policy:
condition: on-failure

volumes:
db-data:
redis-data:

依赖健康状态启动

使用 depends_oncondition 参数可以实现”等待依赖服务健康后再启动”:

1
2
3
4
5
6
7
8
9
10
11
12
13
services:
web:
image: nginx:alpine
depends_on:
api:
condition: service_healthy
# api 服务必须通过健康检查,web 才会启动

api:
image: my-api:latest
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
# ...

这样可以避免”服务启动顺序对,但依赖还没就绪”的问题。

自愈脚本实战

除了 Docker 自带的 HEALTHCHECK,我们还可以配合外部脚本来实现更复杂的自愈逻辑。

完整自愈脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# Docker 容器自愈脚本
# 用途:监控指定容器,发现不健康后自动重启

set -e

CONTAINER_NAME="${1:-my-app}"
MAX_RESTARTS="${2:-3}"
RESTART_WINDOW="${3:-300}" # 5分钟内
LOG_FILE="/var/log/docker-heal.log"

log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}

get_restart_count() {
docker inspect "$CONTAINER_NAME" --format '{{.RestartCount}}' 2>/dev/null || echo "0"
}

get_health_status() {
docker inspect "$CONTAINER_NAME" --format '{{.State.Health.Status}}' 2>/dev/null || echo "none"
}

is_container_running() {
docker inspect "$CONTAINER_NAME" --format '{{.State.Running}}' 2>/dev/null | grep -q "true"
}

heal_container() {
local restart_count=$(get_restart_count)
local health_status=$(get_health_status)

log "Container: $CONTAINER_NAME"
log "Health Status: $health_status"
log "Restart Count: $restart_count"

# 检查容器是否正在运行
if ! is_container_running; then
log "Container is not running, starting..."
docker start "$CONTAINER_NAME"
log "Container started"
return 0
fi

# 如果健康检查失败(不是 starting 或 None),尝试重启
if [[ "$health_status" == "unhealthy" ]]; then
log "Health check failed, restarting container..."
docker restart "$CONTAINER_NAME"

# 等待容器重新启动
sleep 5

# 再次检查健康状态
local new_health=$(get_health_status)
if [[ "$new_health" == "healthy" ]]; then
log "Container recovered successfully"
else
log "Container still not healthy, may need manual intervention"
fi
fi
}

# 主循环
log "Starting container healing monitor for: $CONTAINER_NAME"

while true; do
heal_container
sleep 30 # 每30秒检查一次
done

配合 systemd 使用

将自愈脚本注册为 systemd 服务:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Docker Container Heal Service
After=docker.service
Requires=docker.service

[Service]
Type=simple
ExecStart=/usr/local/bin/docker-heal.sh my-app
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

注册并启动服务:

1
2
3
4
5
6
7
8
9
10
11
12
# 保存服务文件
sudo cp docker-heal.service /etc/systemd/system/

# 重载 systemd
sudo systemctl daemon-reload

# 启用并启动服务
sudo systemctl enable docker-heal
sudo systemctl start docker-heal

# 查看服务状态
sudo systemctl status docker-heal

Prometheus + Alertmanager 监控方案

对于更大规模的生产环境,建议使用 Prometheus 来监控容器健康状态。

###Exporter 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# docker-compose.monitoring.yml
version: '3.8'

services:
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
privileged: true
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
ports:
- "8080:8080"
networks:
- monitoring

node-exporter:
image: prom/node-exporter:latest
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
ports:
- "9100:9100"
networks:
- monitoring

networks:
monitoring:
driver: bridge

告警规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# prometheus/alerts/container.yml
groups:
- name: container_alerts
rules:
# 容器不健康告警
- alert: ContainerUnhealthy
expr: |
container_health_status{status="unhealthy"} == 1
for: 2m
labels:
severity: warning
annotations:
summary: "容器健康检查失败"
description: "容器 {{ $labels.container_label_com_docker_container_name }} 健康检查失败超过2分钟"

# 容器重启过于频繁
- alert: ContainerRestartingTooMuch
expr: |
rate(container_restart_count[5m]) > 0.1
for: 5m
labels:
severity: critical
annotations:
summary: "容器重启过于频繁"
description: "容器 {{ $labels.container_label_com_docker_container_name }} 重启频率过高"

# 容器内存使用过高
- alert: ContainerMemoryUsageHigh
expr: |
(container_memory_usage_bytes / container_spec_memory_limit_bytes) > 0.9
for: 5m
labels:
severity: warning
annotations:
summary: "容器内存使用率过高"
description: "容器 {{ $labels.container_label_com_docker_container_name }} 内存使用率超过90%"

# 容器 CPU 使用过高
- alert: ContainerCPUUsageHigh
expr: |
rate(container_cpu_usage_seconds_total[5m]) > 0.8
for: 10m
labels:
severity: warning
annotations:
summary: "容器 CPU 使用率过高"
description: "容器 {{ $labels.container_label_com_docker_container_name }} CPU 使用率持续过高"

Grafana 看板配置

创建容器监控看板,实时展示健康状态:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
"dashboard": {
"title": "Docker 容器健康监控",
"panels": [
{
"title": "容器健康状态分布",
"type": "piechart",
"targets": [
{
"expr": "count(container_health_status)",
"legendFormat": "{{status}}"
}
]
},
{
"title": "容器重启次数趋势",
"type": "graph",
"targets": [
{
"expr": "rate(container_restart_count[5m])",
"legendFormat": "{{container_label_com_docker_container_name}}"
}
]
},
{
"title": "容器内存使用率",
"type": "graph",
"targets": [
{
"expr": "container_memory_usage_bytes / container_spec_memory_limit_bytes",
"legendFormat": "{{container_label_com_docker_container_name}}"
}
]
}
]
}
}

常见问题解答

Q1:健康检查脚本执行失败会导致容器重启吗?

A:会的。健康检查命令返回非零退出码时,Docker 会将容器标记为 unhealthy,并根据重启策略决定是否重启。所以健康检查脚本一定要确保逻辑正确,避免误判导致无限重启。

Q2:如何区分”容器真的有问题”和”健康检查脚本本身有bug”?

A:建议在健康检查脚本中添加详细日志输出,并配置告警:

1
2
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD /app/healthcheck.sh >> /var/log/healthcheck.log 2>&1 || exit 1

同时监控健康检查日志,及时发现脚本本身的问题。

Q3:健康检查频率如何选择?

A:一般遵循以下原则:

  • 核心服务:间隔 10-30 秒
  • 普通服务:间隔 30-60 秒
  • 批处理任务:可在任务结束时检查一次

间隔越短,故障发现越快,但检查本身也会消耗一定资源。

Q4:容器启动很慢,健康检查等待期应该设多长?

A:--start-period 应该略大于容器实际启动时间。建议在容器中实现”就绪检查”,而不是”存活检查”:

1
2
# 等待容器完全启动(60秒),之后才开始健康检查计时
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:8080/ready || exit 1

Q5:多容器环境下如何协调健康状态?

A:使用 docker-compose 的 depends_on + condition: service_healthy 可以实现基础协调。对于更复杂的场景,建议使用服务网格(如 Istio)或服务发现(如 Consul)来实现分布式健康检查。

总结

本文详细介绍了 Docker 容器健康检查与自愈机制的完整方案:

  1. Docker HEALTHCHECK:利用容器自带的健康检查指令,可以检测进程假死、响应超时等问题
  2. Docker Compose 配置:通过 YAML 声明式配置健康检查和依赖关系
  3. 外部自愈脚本:对于复杂场景,使用脚本实现更灵活的自愈逻辑
  4. Prometheus 监控:集成专业监控系统,实现可观测性
  5. Grafana 可视化:通过看板实时掌握容器状态

实际生产环境中,建议多层防护:

  • 第一层:Docker HEALTHCHECK + restart policy
  • 第二层:外部监控 + 告警
  • 第三层:自动运维平台 + 人工介入

只有多层配合,才能真正实现”故障无人值守、自动恢复”的理想状态。


作者:小六,一个致力于让服务器自己照顾自己的运维工程师

Author:Margrop
Link:http://blog.margrop.com/post/2026-03-27-docker-container-healthcheck-and-self-healing/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可