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

Added /etc/nsswitch.conf file so container's hosts file is respected by Consul - fixes #94 #95

Merged
merged 3 commits into from
Jul 2, 2018

Conversation

aldiyen
Copy link
Contributor

@aldiyen aldiyen commented Apr 25, 2018

The image did not include /etc/nsswitch.conf, and so hostname resolution was using DNS before checking /etc/hosts. This commit fixes that.

See #94

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring nsswitch.conf seems like a good idea to force Gos DNS to use /etc/hosts. Just the one request so that a future alpine version doesn't break building the container.

0.X/Dockerfile Outdated
@@ -46,6 +46,10 @@ RUN mkdir -p /consul/data && \
mkdir -p /consul/config && \
chown -R consul:consul /consul

# set up nsswitch.conf for Go's "netgo" implementation which is used by Consul,
# otherwise DNS supercedes the container's hosts file, which we don't want.
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this eval to a non-zero exit code if for some reason a newer alpine were to include an nsswitch.conf

I think it would be better as RUN test -e /etc/nsswitch.conf || echo 'hosts: files dns' > /etc/nsswitch.conf that way the only way the command fails is if nsswitch.conf didn't exist and wasn't created.

@aldiyen
Copy link
Contributor Author

aldiyen commented Jul 2, 2018

Ah yes, good catch.

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@mkeeler
Copy link
Member

mkeeler commented Jul 2, 2018

For some more context:

When an nsswitch.conf file isn't present on linux, the Go runtime defaults to a hosts nss configuration that should be equivalent to "dns [!UNAVAIL=return] files". This is pretty undesirable as if the upstream DNS responds with NXDOMAIN then that response gets returned without checking the hosts file.

This pr adds an nsswitch.conf file to the image that will change the ordering to check files first and then DNS.

@mkeeler mkeeler merged commit 1fbefba into hashicorp:master 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

Successfully merging this pull request may close these issues.

2 participants