Container healthcheck status via tasks json

603 Views Asked by At

I am trying to fetch container status using the docker remote API. v1.26

I am making /tasks api call to fetch the list of tasks for a node. Is there a way to get the container status from the GET /tasks json which maps to the "Health":{"Status":"healthy" returned when making /containers/json ?

I am basically looking for a health check equivalent of what /container provides in /tasks api

1

There are 1 best solutions below

3
On

From this source: https://docs.docker.com/engine/api/v1.26/#operation/ContainerInspect

I think you can get the information you want by using:

 GET /containers/{id}/json 

In the json returned there are a lot of things, maybe the following is what you are searching for:

"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"

},

edit:

from the GET /tasks example, I see 2 different cases:

State: running

"ID": "0kzzo1i0y4jz6027t0k7aezc7",
"Status": 
{
    "Timestamp": "2016-06-07T21:07:31.290032978Z",
    "State": "running",
    "Message": "started",
    "ContainerStatus": 

    {
        "ContainerID": "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035",
        "PID": 677
    }

},
"DesiredState": "running",

State: shutdown

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

    {
        "ContainerID": "1cf8d63d18e79668b0004a4be4c6ee58cddfad2dae29506d8781581d0688a213"
    }

},
"DesiredState": "shutdown",