Docker Community Forums

Share and learn in the Docker community.

Understanding the 'docker.for.mac.localhost' behavior

(S390xopenwhisk) #1

I’m trying to understand the behavior of the docker.for.mac.localhost pseudo-dns entry in Docker for Mac as part of deploying OpenWhisk with a local CouchDB instance on my Mac. (Caveat – yes, I could try to run CouchDB in the docker-verse, but that really isn’t a good long-term plan.)

So, here’s the behavior I see inside a stock ubuntu:debian image:

root@2d798bc8ec14:/# curl http://docker.for.mac.localhost:5984/
root@2d798bc8ec14:/# dig docker.for.mac.localhost

; <<>> DiG 9.10.3-P4-Ubuntu <<>> docker.for.mac.localhost
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 204
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;docker.for.mac.localhost.	IN	A

docker.for.mac.localhost. 0	IN	A

;; Query time: 0 msec
;; WHEN: Fri Nov 24 14:22:55 UTC 2017
;; MSG SIZE  rcvd: 58

root@2d798bc8ec14:/# curl
root@2d798bc8ec14:/# curl
curl: (7) Failed to connect to port 5984: Connection refused

My response, of course, is “Huh.” DNS resolves to a address, which I expected, but that address can’t be connected explicitly. Meanwhile the underlying address from which it was served ( works like a charm. So why doesn’t docker.for.mac.localhost just resolve to that address?

I’m sure there’s a good reason, but meanwhile I have a Java application that’s not connecting because (I suspect) it resolves the address to and then explicitly uses the numeric IP for connection. Any illumination on underlying implementation and rationale would be greatly appreciated, because I think docker.for.mac.localhost is a great idea, but without understanding how it works, I’m guaranteed to use it incorrectly and create pain.

(Ewgenij Gawrilow) #2

Not being a docker developer I can just speculate: is an address magically mapped to in the host network namespace, while is the gateway address in the bridge network. The latter is used by default for forwarding all outbound traffic to other computers until you start to reconfigure your container’s routing table. So actually they belong to two different networks not reachable from each other.

In the meanwhile the DNS server seems to be fixed. With 17.09.1-ce-mac42, I get:

/ # drill docker.for.mac.localhost
;; docker.for.mac.localhost.	IN	A

docker.for.mac.localhost.	0	IN	A


(Ewgenij Gawrilow) #3

One more hypothesis: the setting “Docker subnet” on the “Advanced” preferences tab seems to have magic influence on docker.for.mac.localhost resolution. It properly works when you enter there.