| 关键参数 | --health-cmd 检查命令(必填) |
|---|---|
| 周期参数 | --health-interval 默认 30s、--health-timeout 默认 30s |
| 其他 | --health-retries 默认 3、--health-start-period 启动宽限 |
示例
示例
docker run -d --name web \
--health-cmd 'wget -qO- http://localhost/ >/dev/null || exit 1' \
--health-interval 30s --health-timeout 5s --health-retries 3 \
nginx:1.27-alpine
docker inspect -f '{{.State.Health.Status}}' web状态会经历 starting → healthy 或 unhealthy;unhealthy 只是标记,不会自动重启容器(Swarm/K8s 另有编排行为)。