首页 > 解决方案 > Docker swarm 堆栈文件运行状况检查命令无法按预期工作

问题描述

我遇到了以下问题:

容器使用以下运行状况检查配置运行(test有问题)

    healthcheck:
      test: ["CMD-SHELL", "curl -s -X GET http://127.0.0.1:5000/actuator/health", "|", "grep 'UP'"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 10s

在运行时,我看到只考虑了 healthcheck 测试命令 ( curl -s -X GET http://127.0.0.1:5000/actuator/health) 的第一部分。端点以状态回答:Down,但通过了健康检查 - "Status": "healthy"

docker inspect 1f074dc72c6d | grep -i -A 10 health
            "Health": {
                "Status": "healthy",
                "FailingStreak": 0,
                "Log": [
                    {
                        "Start": "2019-12-10T11:37:46.215783033Z",
                        "End": "2019-12-10T11:37:46.315844469Z",
                        "ExitCode": 0,
                        "Output": "{\"status\": \"DOWN\"}"
                    },
                    {
                        "Start": "2019-12-10T11:38:16.346253717Z",
--
            "Healthcheck": {
                "Test": [
                    "CMD-SHELL",
                    "curl -s -X GET http://127.0.0.1:5000/actuator/health",
                    "|",
                    "grep 'UP'"
                ],
                "Interval": 30000000000,
                "Timeout": 3000000000,
                "StartPeriod": 10000000000,
                "Retries": 3

标签: dockerdocker-composeyamldocker-swarmdocker-stack

解决方案


CMD-SHELL接受一个参数,字符串被传递给处理字符串解析的shell:

test: ["CMD-SHELL", "curl -s -X GET http://127.0.0.1:5000/actuator/health | grep 'UP'"]

推荐阅读