Docker Community Forums

Share and learn in the Docker community.

Resolve hosts computer /etc/hosts entries from within docker (works on Mac, but not on Linux)

docker

(Cytopia) #1

Hi everybody,

I have setup a LAMP stack (https://github.com/cytopia/devilbox) with dynamically configured mass virtual hosting.

Apache/Nginx are listening on my host computer on 127.0.0.1:80, so that I can use my Host browser to access my projects served via the docker.
For this to work, I need to add my domains (e.g.: example.loc) into my host computers etc/hosts

I added a check inside my docker that will check if a specific /etc/hosts entry exists on the docker host.
This is accomplished inside my PHP docker via:

getent hosts example.loc

However, only when running the whole setup on OSX it works.
When running the docker setup under Linux, the PHP docker is not able to resolve the docker hosts /etc/hosts

Are there any differences between the two or something that I am missing?

What is another good way from inside the docker to use the hosts /etc/hosts configuration?