Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve hostnames to Docker containers from the host?

I understand Docker runs a magical dns on 127.0.0.11, so I figured I'd try

nslookup mycontainername 127.0.0.11

where mycontainername is, of course, the name of the container I'm trying to access. However, that timed out.

;; connection timed out; no servers could be reached

What am I doing wrong? I'm on Docker 1.10.3. If it helps, I'm pulling up a bunch of containers using docker-compose 1.6.2.

EDIT This is a duplicate of Docker 1.10 access a container by it's hostname from a host machine

like image 375
Morpheu5 Avatar asked Mar 23 '16 17:03

Morpheu5


People also ask

How do docker containers resolve DNS?

Docker is coded in a smart way. When you run new container on the docker host without any DNS related option in command, it simply copies host's /etc/resolv. conf into the container.

How do I connect to docker host?

Use --network="host" in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.


1 Answers

There is an excellent solution for this and it has been answered in this post: https://stackoverflow.com/a/51125399/9270227. It is basically just a lightweight container called docker-hoster that does all the heavy lifting for you.

like image 74
Shōgun8 Avatar answered Sep 28 '22 10:09

Shōgun8