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

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!

1 Like

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?

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>)

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, but is that accessible from the host?

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

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 \

Running a test container

docker run --hostname nginx

Testing it

PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.099 ms
64 bytes from icmp_seq=2 ttl=64 time=0.069 ms