cytopia/devilbox

Access docker hosts `/etc/hosts` from inside the PHP-docker (works on OSX, not on Linux)

cytopia opened this issue · 5 comments

In order to check if the hostnames for mass virtual hosting have been setup correctly in vhosts.php the php docker needs to be able to resolve the docker hosts dns entries from the hosts /etc/hosts file.

This is done in the PHP docker via getent hosts example.loc

However, this only works with a docker setup under OSX, but not with a docker setup under Linux.

I also created a ticket to get more information.

If anybody has a nice/better solution please let me know.

Thinkings:

  • Alternatively add minimal and leight-weight DNS server as container
cebe commented

I have not looked into any details here, but could the --add-host option of docker run maybe help you?

$ docker help run

[...]

Options:
--add-host value Add a custom host-to-IP mapping (host:ip) (default [])
[...]

@cebe Thanks for the info

I think --add-host adds a single entry to /etc/hosts, however I need some way to auto-sync the hosts /etc/hosts values with the ones from the containers.

This already seems to work on OSX, but strangely not on Linux...

self-contained DNS docker could be an options:

https://github.com/phensley/docker-dns

Will be done from inside the docker container via: cytopia/docker-bind#1
and from outside the docker container via Javascript ajax calls over the host DNS records