1

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

sam
  • 568
  • 1
  • 8
  • 16

1 Answers1

0

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",
tgogos
  • 23,218
  • 20
  • 96
  • 128
  • I was wondering if there is a way for getting this information for the /tasks API. I am looking to get container info across all swarm nodes via the node and task API. Apparently you can only get container info for the node you are querying – sam May 22 '17 at 00:31
  • `/tasks` gives you some kind of information plus the `ContainerID` inside the `ContainerStatus`. I don't know if this fits your needs – tgogos May 22 '17 at 07:50
  • 1
    it does partly but does not return the container status (health check). I was hoping it would do that I dont have to inspect each container – sam May 22 '17 at 16:11