Docker Community Forums

Share and learn in the Docker community.

Resolve containers from host by network-alias or container name or host

docker

(Zzvara) #1

I’m running Docker 1.12.1. Got a few containers on a user-network (bridge type), each container assigned a --network-alias. Containers resolve each other correctly, but the host is just simply not able to resolve any container by its network alias or host name.

How can one make the host to be able to resolve names of containers on a any user network? Thanks!


(Zzvara) #2

Since this question does not receive enough attention, I assume that it is in feasible or just very hard to accomplish in contrast to how natural the requirement is.

Could someone make a hint at least?


(John Harris) #3

Don’t believe the network aliases have any effect for host -> container connections. It’s just another alias accessible via DNS from containers inside the specificed bridge network. Or you could map a port and then just connect to it via localhost:<mapped_port>.

You could achieve what you want by putting an entry into your host’s /etc/hosts file mapping your alias to the IP address of the container (accessed via docker inspect <container>)


(Zzvara) #4

Yes, this is what I have right now, but unfortunately managing tens of containers statically like that is not a convenient way of doing this. Is there any way to access the embedded DNS on a user defined network maybe? It could work. I see all the containers go for 127.0.0.55, but is that accessible from the host?


(Markbsigler) #5

create an additional bridge network and connect each of the containers to it, should allow name resolution


(Defreitas) #6

Take a look at this answer, this make possible to run a container and solve it by hostname at host machine, it would be helpful for development

docker run --rm --hostname dns.mageddo --name dns-proxy-server -p 5380:5380 \
  -v /opt/dns-proxy-server/conf:/app/conf \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /etc/resolv.conf:/etc/resolv.conf \
  defreitas/dns-proxy-server

Running a test container

docker run --hostname nginx.dev.intranet nginx

Testing it

ping nginx.dev.intranet
PING nginx.dev.intranet (172.17.0.5) 56(84) bytes of data.
64 bytes from 172.17.0.5: icmp_seq=1 ttl=64 time=0.099 ms
64 bytes from 172.17.0.5: icmp_seq=2 ttl=64 time=0.069 ms