Docker Community Forums

Share and learn in the Docker community.

Service Discovery in Swarm Mode

Expected behavior

Services deployed in Swarm mode can be accessed each other by names.

Actual behavior

Services deployed in Swarm mode can not be accessed each other by names, but using IP is OK.

Additional Information

I tested this in a newly-created docker for aws cluster (with the GA couldformation).

Steps to reproduce the behavior

  1. I created a zookeeper service, by sth like this:
    docker service create --name zookeeper --hostname zookeeper …
  2. I wanted to create a kafka service, and it will access the zookeeper service by the name “zookeeper”. But it didn’t work. I need to use the IP address of the zookeeper service.

https://docs.docker.com/engine/swarm/ says

Service discovery: Swarm manager nodes assign each service in the swarm a unique DNS name and load balances running containers. You can query every container running in the swarm through a DNS server embedded in the swarm.

But it does not say how it works.

For services to discover one another with DNS, they have to be on the same network: https://docs.docker.com/engine/swarm/networking/#/use-swarm-mode-service-discovery

Note that services can be attached to multiple networks if desired.

Thanks a lot, @friism!