-
Notifications
You must be signed in to change notification settings - Fork 437
Description
Folks, why not always rely on system hostname resolver? Do I miss some specific usage scenario which requires usage of inet_res?
I believe that
Line 126 in 436f7b2
| getbyname(Hostname, Type) -> |
case (catch inet:gethostbyname(Hostname, InetType)) of
{'ok', #hostent{h_addr_list=AddrList}} ->
lists:usort(AddrList);
_ ->
[]
Here are details on the issue I have: I'm working on organizig local dev environment based on Docker/Podman compose.
The problem I'm trying to solve is how to make some services working inside compose environment and outside environment at the same time.
Idea is to use magic hostname such as dev.local and use it in URL of all HTTP services, no matters where they are running.
On the dev workstations this magic host is suppose to be added into /etc/hosts
127.0.0.1 dev.local
::1 dev.local
This solution is almost working. The only issue I have is with components based on HTTPoison/hackney. For some reason hackney is trying to resolve host names in URL over DNS first and only then is falling back to the system resolver.
And here we come to another "feature" of Docker Desktop: it over its internal DNS server for some reason returns records from the system /etc/hosts. Leading to that the magic host is resolving to 127.0.0.1 over DNS and to 192.168.65.254 over system resolver.
iex(registry@96282b60e624)3> :inet.getaddr(~c'dev.local', :inet)
{:ok, {192, 168, 65, 254}}
iex(registry@d7a9ee9a5a2d)1> :inet_res.getbyname(~c'dev.local', :a)
{:ok, {:hostent, ~c"dev.local", [], :inet, 4, [{127, 0, 0, 1}]}}
iex(registry@d7a9ee9a5a2d)2>