I'm trying to use dockerode to access the Docker API.
My goal is to get container data for all containers in the multi node swarm.
It appears that docker.listContainers( {all: true } )
is scoped to only returns containers running on the calling node, in my case my manager node.
https://docs.docker.com/engine/api/v1.37/#operation/ContainerList
How do we use dockerode to get a list of all the containers in a swarm?
How do we use dockerode to get a list of all the containers associated with a service?
On the command line, you can get the container id using docker service ps <service_name>
to get the container id, and then call inspect on container.
$ docker service ps classifier_8
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
m1x8e2w5dyvr classifier_8.1 scuba:qa-latest master Running Running 26 minutes ago
8a04d2e18ee9 classifier_8.2 scuba:qa-latest worker-0 Running Running 26 minutes ago
a6b48751780b classifier_8.3 scuba:qa-latest worker-1 Running Running 26 minutes ago
$ docker inspect a6b48751780b
[{...}]
Even a simple example of calling dockerode.getContainer(a6b48751780b) returns a 404. Calling m1x8e2w5dyvr returns the expected data as its on the manager node.