Fix Docker not using /etc/hosts on Mac OS X

On my MacBook with Mac OS X 10.11 (El Capitan) and Docker 1.12.0, Docker did not read manually set DNS entries from the /etc/hosts file.

When I executed “docker push” for example, this resulted in “no such hosts” errors:

Put http://shuttle:5000/v1/repositories/webfrontend/: dial tcp: lookup shuttle on no such host

On Mac OS, Docker is running in a host container itself. Thus, you’ll have to add DNS entries to the container’s /etc/hosts file. To fix it, get into the running Docker Host:

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

This took a while on my machine, I needed to press Ctrl+C for the login prompt to show up. Log in with “root” (no password required).

Edit the /etc/hosts file in the Docker Host using vi:

vi /etc/hosts

Note: Insert after pressing “i”, save by pressing Escape and then type “:wq” <Return>.

Restart the Docker Daemon with:

service docker restart

Detach from the screen session by pressing Ctrl+A, then press D.

Docker should now use the correct /etc/hosts entries.

2 thoughts on “Fix Docker not using /etc/hosts on Mac OS X”

  1. Thanks for the workaround!

    Did you realize that if we restart the docker service on OSX, all the /etc/hosts config is gone and the problem persists.

    What would be a persistent solution?

    1. Hi Ahmet! You’re right: The setting is gone after a restart. I don’t have a solution for it right now. Please let me know if you find one 🙂

Comments are closed.