diff --git a/infrastructure/docker-compose.staging.yml b/infrastructure/docker-compose.staging.yml index ef28eac..ae40ed2 100644 --- a/infrastructure/docker-compose.staging.yml +++ b/infrastructure/docker-compose.staging.yml @@ -74,7 +74,9 @@ services: ports: - "8081:8080" healthcheck: - test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/health/ready || exit 1"] + # 探针用 127.0.0.1 而非 localhost:busybox wget 解析 localhost 时可能优先取 ::1, + # 而服务若只绑 IPv4 会导致探针假失败(本地栈的 nginx 已实测踩到)。 + test: ["CMD-SHELL", "curl -f http://127.0.0.1:8080/api/v1/health/ready || exit 1"] interval: 30s timeout: 10s retries: 3 diff --git a/infrastructure/docker-compose.yml b/infrastructure/docker-compose.yml index 2e022d1..b832cc9 100644 --- a/infrastructure/docker-compose.yml +++ b/infrastructure/docker-compose.yml @@ -85,7 +85,9 @@ services: ports: - "8085:8080" healthcheck: - test: ["CMD-SHELL", "wget -qO /dev/null http://localhost:8080/api/v1/health/live || exit 1"] + # 与 nginx 同理,用 127.0.0.1 而非 localhost:backend 当前恰好双栈监听(:::8080), + # 故 localhost 解析成 ::1 也能通;但探针不应依赖「服务恰好绑了 IPv6」这一偶然事实。 + test: ["CMD-SHELL", "wget -qO /dev/null http://127.0.0.1:8080/api/v1/health/live || exit 1"] interval: 30s timeout: 10s retries: 3 @@ -112,7 +114,13 @@ services: volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro healthcheck: - test: ["CMD-SHELL", "wget -qO /dev/null http://localhost/nginx-health || exit 1"] + # 探针地址必须写 127.0.0.1,不能写 localhost。 + # 实测:nginx 的 `listen 80` 只绑 IPv4(容器内 netstat = 0.0.0.0:80), + # 而 /etc/hosts 中 `::1 localhost` 同样存在,busybox wget 解析 localhost 时优先取 ::1 + # → 探针连 IPv6 回环被拒(Connection refused)→ 容器被标 unhealthy, + # 但服务其实完全正常(宿主 curl http://localhost:6688/nginx-health = 200)。 + # 这是一类「探针与被探对象脱钩」的假告警,还会连带拖垮 depends_on: service_healthy。 + test: ["CMD-SHELL", "wget -qO /dev/null http://127.0.0.1/nginx-health || exit 1"] interval: 30s timeout: 10s retries: 3