How to get all the container details running in an overlay network from swarm node

We need to call docker api programatically. But /container/json api call only list container on that particular node but we want list of all the container across various docker nodes from swarm node.

In general, the work units in a swarm are services, which instantiate tasks. If you’re using the API, you can create a service via “POST /services/create”. You can inspect a service via “GET /services/{id}”. You can list and inspect the tasks via “GET /tasks” or “GET /tasks/{id}”. Task inspection will also show which networks the task is attached to, what node id it’s running on, the service id it’s associated with, and so forth.

Correct /task api give all the details but we are also need “Status”: “Up 18 minutes (healthy)” field which is there in /container api. Is there any way we can get status (healthy/unhealthy) of a container which is alive using /task api.

For the status of any health checks, you may need to go one level further down and inspect the container associated with the task. To do that, in the results of the task inspection, look for Status.ContainerStatus.ContainerID. Using that ContainerID, you can inspect/ GET the /containers/{Status.ContainerStatus.ContainerID}/json and look at State.Health. For example, you can see Health.Status and Health.Log.

But to call /inspect/{containerid}/jsom we need to invoke this api on each and every docker node as swarm node alone won’t be able to give details about all the container id? If that is the case then there would be lot of network calls.