Say I have a Swarm of 3 nodes on my local system. And I create a service say Drupal with a replication of 3 in this swarm. Now, say each of the node has one container each running Drupal. Now when I have to access this in my browser I will have to use the IP address of one of the nodes <IP Address>:8080
to access Drupal.
Is there a way I can set a DNS name for this service and access it using DNS name instead of having to use IP Address and port number?
Asked
Active
Viewed 1,155 times
0

adi
- 143
- 11
1 Answers
0
You need to configure the DNS server that you use on the host making the query. So if your laptop queries the public DNS, you need to create a public DNS entry that would resolve from the internet (on a domain you own). This should resolve to the docker host IPs running the containers, or an LB in front of those hosts. And then you publish the port on the host to the container you want to access.
You should not be trying to talk directly to the container IP, these are not routeable from outside of the docker host. And the docker DNS used for service discovery is for container to container communication. This is separate from communication outside of docker that goes through a published port.

BMitch
- 231,797
- 42
- 475
- 450
-
Is there any inbuilt feature in docker swarm that will enable DNS names for my services running on swarm? – adi Mar 24 '21 at 15:05
-
1@adi Within containers running in swarm, DNS discovery is enabled by default, using the service name. This is the same service discovery available with docker-compose. https://docs.docker.com/compose/networking/ – BMitch Mar 24 '21 at 15:14