Docker Community Forums

Share and learn in the Docker community.

Physical hostnames in overlay netowrk dns

Hi,

I have deployed some services in a new overlay network. From the containers I can ping the other service names and everything works perfectly.

I’d like to know If it would be possible to resolve the ip of the physical hostnames. It is, I can query the IP of the physical hostname but it is not able to resolve the name from inside the container.

¿any clue?
Thanks a lot in advance,

In general you don’t want to use Dockers private IP Adresses to reference another container, since they’re dynamic in general. In fact, i don’t know if you can reserve an internal IP address, but i doubt it since it seems kinda strange to me.

You can try to create a network and attach an alias for each container

services:
  web
    networks:
        network.local:
          aliases:
            - web.network.local
  ...
  db:
    networks:
        network.local:
          aliases:
            - db.network.local
  ...
networks:
  network.local:

I don’t know if that’s something that will help with your usecase but you can try. :slight_smile:

Hi,

Thanks a lot for your answer. What I mean is that I want to ping by name the physical hostname (nodes where swarm is running).

Query other services and containers work perfectly within my ingress network.

Thanks a lot.

Why would you even want to resolve the hostname for an ip? What’s the use case??
Usualy you want the other way arround, which should work ootb.

If you need dns servers in the container that are different than the the one your hosts, take a look at:

Though, usualy it is sufficient to declare extra_hosts` which will result as entries in the container’s /etc/hosts file:

With extra_hosts it is possible to add several entries with the same hostname and different ips, which result in distinct entries in /etc/hosts. Though, for name resolution, always the first result is returned. The entries will not be added to the overlay’s network dns.

Hi meyay,

The use case is quite simple. I have deployed an opennebula orchestrator as a container and I want it to reach the physical hosts where my VMs will run. Communication is stablished with ssh.

Thanks a lot.

Thanks for the information you provided, they are very helpful to me