Skip to content

How to read the IP addresses of swarm tasks? #1140

@kamalhakim

Description

@kamalhakim

Hi,

Is there any way to read the ip address of swarm tasks?

I make a docker client poniting to the leader of the swarm via:

   DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("unix:///var/run/docker.sock").build();
   DockerClient client = DockerClientBuilder.getInstance(config).build();

I read the tasks of a service by:

    List<Task> tasks = client.listTasksCmd().withServiceFilter(serviceName).exec();

Then I tried the following two ways to find the ip address of a task:

  1. fetching continer by id:
   TaskStatus status = task.getStatus();
   TaskStatusContainerStatus containerStatus = status.getContainerStatus();
   String containerID = containerStatus.getContainerID();
   List<String> idfilter = new ArrayList<>();
   idfilter.add(id);
   List<Container> list = client.listContainersCmd().withShowAll(true).withIdFilter(idfilter).exec();
  1. fetching container from overlay network:
   List<Network> netList = client().listNetworksCmd().withNameFilter(new String[]{netName}).exec();
   Network network = netList.get(0);
   Map<String, Network.ContainerNetworkConfig> containers = network.getContainers();

But both return an empty list - or they do not return the containers that are placed on other swarm nodes.

Is this feature supported in the API?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions