.localhost DNS doesn't resolve in browsers other than Chrome

Accessing web servers running on http://mycontainer.localhost works fine on Chrome, but not in other browsers (tested Safari, Firefox and Opera). As far as I can tell, the DNS isn’t resolving.

If it’s any help, ping mycontainer.localhost results in Unknown host in the terminal as well.

Information

Docker for Mac: version: mac-v1.12.0-beta16.2
OS X: version 10.11.5 (build: 15F34)
logs: /tmp/20160622-122152.tar.gz
failure: No error was detected
[OK] docker-cli
[OK] app
[OK] menubar
[OK] virtualization
[OK] system
[OK] osxfs
[OK] db
[OK] slirp
[OK] moby-console
[OK] logs
[OK] vmnetd
[OK] env
[OK] moby
[OK] driver.amd64-linux

Mac OS 10.11.5

Steps to reproduce the behavior

  1. docker run -it --name mycontainer -p 80:80 -d kitematic/hello-world-nginx
  2. Open Chrome, go to http://mycontainer.localhost (works)
  3. Open Firefox, go to http://mycontainer.localhost (no worky!)

There’s no such thing as subdomains of localhost. By near-universal convention, localhost resolves to the IPv4 address 127.0.0.1 and the IPv6 address ::1.

When you docker run -p 80:80, you make your local host publish port 80 in the container as port as port 80 on the host, so you can access http://localhost/… and it redirects to the container. If you want to run another process, you need to pick another port: docker run -p 8888:80 otherimage makes http://localhost:8888/… go to the other container.

Err that’s true in general @dmaze, but Docker for Mac does something fancy here, much as one would do with DNSMasq. In this case, localhost isn’t normal 127.0.0.1 – I think Docker for Mac/Windows includes an internal DNS server that allows you to use URLs such as this (see here).

Did you try my steps? Hopefully you get the same result as me :slight_smile:

As anyone found a solution to this issue?

My workaround is to use chrome with *.docker.localhost and expose a port if I need to test in Safari/Firefox. Would be nice to use the domain across the board.