Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

fix(dns): /etc/hosts was ignored by traefik #75

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

kopax
Copy link

@kopax kopax commented Dec 12, 2019

Fix traefik/traefik#6001

What does this PR do?

It create the missing /etc/nsswitch.conf.

Motivation

During proxying, traefik is performing a DNS resolution. This DNS resolution is skipping /etc/hosts file. This can cause unwanted DNS resolution, especially when using hostname as fqdn in marathon.

If you use /etc/hosts file for some resolution, this will fix it. If you use a real fqdn in marathon on a private network, you will still have to properly configure DNS serveur in traefik host.

Fix traefik/traefik#6001

### What does this PR do?

It create the missing `/etc/nsswitch.conf`.

### Motivation

During proxying, traefik is performing a DNS resolution. This DNS resolution is skipping `/etc/hosts` file. This can cause unwanted DNS resolution, especially when using hostname as fqdn in marathon.

If you use `/etc/hosts` file for some resolution, this will fix it. If you use a real fqdn in marathon on a private network, you will still have to properly configure DNS serveur in traefik host.
@ldez
Copy link
Contributor

ldez commented Dec 12, 2019

Related to #42

@kopax
Copy link
Author

kopax commented Dec 12, 2019

I am curious, if this was already merged, why was it removed?

@kopax
Copy link
Author

kopax commented Dec 12, 2019

No clue why travis get this:

 ---> Running in d7c16a0f1158
OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
The command "./.ci/test.sh" exited with 1.

Copy link
Contributor

@dduportal dduportal left a comment

Choose a reason for hiding this comment

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

  • Build is failing on a sh error, because you updated a Docker image based on scratch (ref. https://hub.docker.com/_/scratch), which does NOT contains any sh or bash shell, resulting in failure of executing any RUN command. Suggestions proposed to fix this.
  • Can you remove the comments, it's verbose and doesn't provide any value as all the history is kept in git and can be resolved with git blame
  • Can add the commands to the alpine image please?

scratch/tmplv2.Dockerfile Outdated Show resolved Hide resolved
scratch/tmplv1.Dockerfile Outdated Show resolved Hide resolved
scratch/Dockerfile Outdated Show resolved Hide resolved
scratch/Dockerfile Outdated Show resolved Hide resolved
scratch/tmplv1.Dockerfile Outdated Show resolved Hide resolved
scratch/tmplv2.Dockerfile Outdated Show resolved Hide resolved
@ldez ldez self-requested a review December 12, 2019 18:36
kopax and others added 7 commits December 12, 2019 21:19
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
@kopax
Copy link
Author

kopax commented Dec 12, 2019

What command are required in the alpine image ? It seems they already have /etc/resolv.conf since you import them from another image.

Copy link
Contributor

@dduportal dduportal left a comment

Choose a reason for hiding this comment

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

What command are required in the alpine image ? It seems they already have /etc/resolv.conf since you import them from another image.

  • The scratch image copies files from the traefik:v*-alpine : there is a dependency so you must change the alpine change.
  • The alpine image is built first. It does not have any nsswitch.conf file. So you have to create one. As Alpine has a sh binary within, you can totally use the same RUN command that you specified initially: RUN [ ! -e /etc/nsswitch.conf ] && echo "hosts: files dns" > /etc/nsswitch.conf
  • Yes, there is already a file /etc/resolv.conf in the alpine image: this file is mounted by docker when container are run, providing the DNS resolvers to your container as explained in https://docs.docker.com/v17.09/engine/userguide/networking/default_network/configure-dns/ . Therefore this is out of the scope of your PR, since you request to use the /etc/hosts files before trying DNS resolution.

scratch/Dockerfile Outdated Show resolved Hide resolved
@kopax
Copy link
Author

kopax commented Dec 14, 2019

Thanks for providing all the details, I've updated the PR with requested change.

Copy link
Contributor

@dduportal dduportal left a comment

Choose a reason for hiding this comment

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

Thanks, you're almost there.

I've added some suggestions, as Traefik's version comes from an environment variable for the templates (because it changes over time and we don't update all occurences by hand).

Once you'll have fixed the templates, can you run the following command from the root of the repository to update the Dockerfiles from templates please?

bash update.sh v2.1.1

scratch/tmplv1.Dockerfile Outdated Show resolved Hide resolved
scratch/tmplv1.Dockerfile Outdated Show resolved Hide resolved
scratch/tmplv2.Dockerfile Outdated Show resolved Hide resolved
scratch/tmplv2.Dockerfile Outdated Show resolved Hide resolved
@dduportal
Copy link
Contributor

Side question: what is the status of this feature request for the Windows Docker images?

kopax and others added 4 commits December 23, 2019 22:13
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
Co-Authored-By: Damien Duportal <damien.duportal@gmail.com>
@kopax kopax requested a review from dduportal December 25, 2019 01:35
@dduportal
Copy link
Contributor

Hi @kopax , can you ensure that you're setting the parent image to 2.1.1-alpine please? You can check the Travis-CI build logs, or run the command by yourself to reproduce the error on your local change.

@kopax
Copy link
Author

kopax commented Sep 13, 2020

Hi @dduportal too much time have passed since the traefik/traefik#6012 and I lost track of what is needed. What about the alpine image? Was this never fixed in recent traefik version? I am still running on 2.1.1 with this fix but perhaps it's time to close this?

@dduportal
Copy link
Contributor

Hi @kopax , I am not involved anymore in the Traefik project. I would delegate to @ldez and @SantoDE to take care of your request instead :)

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.

marathon and traefik 2.1 not reading /etc/hosts of container resulting in 504 Gateway timeout
3 participants