2

I create two service, service-a(3 replies) and service-b(5 replies). They are in micro overlay network.

I want to get all container ip from dns.

# docker run --rm --network micro alpine nslookup service-a

But only get one ip. Is there has anyway to get all IPs address of some service using dns?

XGHeaven
  • 1,696
  • 2
  • 14
  • 17

2 Answers2

0

Use tasks.<service-name> to get all containers belonging to particular service.

Sebi2020
  • 1,966
  • 1
  • 23
  • 40
-1

You can use docker inspect to get the virtual IP of a service:

NETWORK_ID=$(docker network ls -q --no-trunc --filter name=micro) && docker service inspect service-a -f "{{range \$i, \$value := .Endpoint.VirtualIPs}} {{if eq \$value.NetworkID \"$NETWORK_ID\" }}{{$value.Addr}}{{end}}{{end}}"

This one line command finds the network ID then use it in a docker inspect to get only the services virtual IPs in this network, using the -f (format) parameter

Constantin Galbenu
  • 16,951
  • 3
  • 38
  • 54