Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Consul uses DNS before container's hosts file when resolving hostnames #94

Closed
aldiyen opened this issue Apr 25, 2018 · 1 comment
Closed

Comments

@aldiyen
Copy link
Contributor

aldiyen commented Apr 25, 2018

On Mac OS X, Consul doesn't seem to be respecting the container's hosts file when resolving hostnames.

To reproduce:

  • Explicitly define a hosts file entry for container (via --add-host argument to run command) for a given hostname (e.g. --add-host=my-laptop:192.168.0.7)
  • In the host machine's hosts file, set the same hostname to a different IP address (e.g. 127.0.0.1 my-laptop)
  • Configure health check in Consul referencing that hostname (tested with HTTP health check, pointing to something like https://my-laptop:443/healthCheck)
  • Observe that the health check fails with error HTTP request failed: Get https://my-laptop:443/healthCheck: dial tcp 127.0.0.1:443: getsockopt: connection refused when

Using docker exec to run ping or curl against this same hostname from within the Consul container resolves to the properly configured IP address. It's only the consul process that's resolving incorrectly. I'm not an expert on Docker, so I'm not totally sure what's going on, but it may be due to the way the consul process is executed via the docker-entrypoint.sh script.

@aldiyen
Copy link
Contributor Author

aldiyen commented Apr 25, 2018

After some additional troubleshooting, it seems that this is related to the way Go's netgo DNS resolver works on Linux, and this sort of issue has cropped up in other projects. I believe I've fixed the problem. Will make a PR in a few once I do some more testing.

Similar issues in other projects:

@aldiyen aldiyen changed the title (Mac OS X) Consul not using container's hosts file Consul not using container's hosts file Apr 26, 2018
@aldiyen aldiyen changed the title Consul not using container's hosts file Consul uses DNS before container's hosts file when resolving hostnames Apr 26, 2018
@mkeeler mkeeler closed this as completed in 1fbefba Jul 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant