17

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

Community
  • 1
  • 1
Morpheu5
  • 2,610
  • 6
  • 39
  • 72

2 Answers2

2

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.

Shōgun8
  • 482
  • 10
  • 20
  • That's a cool workaround, I would consider that but I'm not a huge fan of random software that touches my configuration files. Still, pretty cool workaround, thanks! – Morpheu5 Jan 31 '20 at 22:04
  • 1
    That's a valid concern. But the python script is open-source; so what I hope to do is to port that script to a Bitnami minideb container, and leverage the tecnativa/docker-socket-proxy image to gain access to the docker API. – Shōgun8 Feb 01 '20 at 02:36
  • That'd be certainly helpful. Another workaround I found is to have an alias (I called it `dip`) that prints the IP of a named container, so I can do the likes of `curl \`dip container_name\``. Not ideal, but OK for what it turned out to be what I really needed. – Morpheu5 Feb 02 '20 at 16:13
1

In the documentation it implies that this only works if you've explicitly created a network and attached the containers to them. Try something like:

docker network create -d bridge --subnet 172.25.0.0/16 isolated_nw
docker network connect isolated_nw mycontainername

And see if you can use 127.0.0.11 (worked for me on version 1.10.3)

For more information see this ticket.

mcw
  • 26
  • 1
  • Thanks, I'll try this when I'm back at the office and come back to you. – Morpheu5 Mar 23 '16 at 22:07
  • OK, that specifically doesn't work for me. I created the network (172.25/16 instead of 172.20/16 which is where my containers were, because docker was complaining of overlapping ipv4 addresses) and connected the containers to it. OTOH, I kind of assumed that docker-compose did actually create a network, and in fact it did, as confirmed by `docker network ls`. – Morpheu5 Mar 24 '16 at 09:16
  • Everything else works: for example, I can ping containers with their names from within other containers. I suspect that's because of the `docker-compose`-created network. – Morpheu5 Mar 24 '16 at 09:34
  • Not sure what OS you're using, but in the ticket listed above, some folks were having issues because of firewall software running on their machines. It may be worth making sure that there are no IP filters running on your machine. Also, take a loot at `/etc/resolv.conf`. On my machine the nameserver 127.0.0.11 isn't in that file until after I add the network to the container. Before it just passes through to my host's server IP – mcw Mar 24 '16 at 12:18
  • 1
    I'm on Ubuntu 15.10, but I'll be on CentOS 7 in production. I made sure I have no firewall blocking (in fact, everything is allowed from everywhere on any port and protocol) and I even added the IP to my `/etc/resolv.conf` but it did not make a difference. – Morpheu5 Mar 24 '16 at 13:26