【问题标题】:Container healthcheck status via tasks json通过任务 json 的容器健康检查状态
【发布时间】:2017-05-21 21:09:35
【问题描述】:

我正在尝试使用 docker 远程 API 获取容器状态。 v1.26

我正在调用 /tasks api 来获取节点的任务列表。有没有办法从 GET /tasks json 获取容器状态,它映射到制作 /containers/json 时返回的 "Health":{"Status":"healthy" ?

我基本上是在寻找 /container 在 /tasks api 中提供的健康检查功能

【问题讨论】:

    标签: docker remoteapi docker-engine


    【解决方案1】:

    来自此来源:https://docs.docker.com/engine/api/v1.26/#operation/ContainerInspect

    我认为您可以通过以下方式获得所需的信息:

     GET /containers/{id}/json 
    

    在返回的json里面有很多东西,可能你要找的就是下面这个:

    "State": 
    
    {
    
        "Error": "",
        "ExitCode": 9,
        "FinishedAt": "2015-01-06T15:47:32.080254511Z",
        "OOMKilled": false,
        "Dead": false,
        "Paused": false,
        "Pid": 0,
        "Restarting": false,
        "Running": true,
        "StartedAt": "2015-01-06T15:47:32.072697474Z",
        "Status": "running"
    
    },
    

    编辑:

    GET /tasks 示例中,我看到了两种不同的情况:

    状态:运行

    "ID": "0kzzo1i0y4jz6027t0k7aezc7",
    "Status": 
    {
        "Timestamp": "2016-06-07T21:07:31.290032978Z",
        "State": "running",
        "Message": "started",
        "ContainerStatus": 
    
        {
            "ContainerID": "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035",
            "PID": 677
        }
    
    },
    "DesiredState": "running",
    

    状态:关机

    "ID": "1yljwbmlr8er2waf8orvqpwms",
    "Status": 
    {
        "Timestamp": "2016-06-07T21:07:30.202183143Z",
        "State": "shutdown",
        "Message": "shutdown",
        "ContainerStatus": 
    
        {
            "ContainerID": "1cf8d63d18e79668b0004a4be4c6ee58cddfad2dae29506d8781581d0688a213"
        }
    
    },
    "DesiredState": "shutdown",
    

    【讨论】:

    • 我想知道是否有办法为 /tasks API 获取此信息。我希望通过节点和任务 API 跨所有 swarm 节点获取容器信息。显然您只能获取您正在查询的节点的容器信息
    • /tasks 为您提供一些信息以及ContainerStatus 中的ContainerID。我不知道这是否符合您的需求
    • 它只做部分但不返回容器状态(健康检查)。我希望它会这样做,我不必检查每个容器
    猜你喜欢
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    相关资源
    最近更新 更多