DNS resolution in Traefik - would like to use a host entry

I have traefik 1.7 running in docker on centos
Although it runs in Docker, traefik is using the "file" endpoints for the purpose of a proxy to another web server which resides on a separate VM. I have traefik working as a proxy for about 4 web servers. Traefik uses dns lookup to find each of those web servers and is working well. My issue is that I would like to add another web server but will use a local host entry to resolve the DNS.

I would like to have this flow:

browser -> Traefik -> web server

on the system that runs docker and hosts traefik, I modified /etc/hosts to point traefik to another web server. The result is the /etc/hosts is not used but DNS is used
I modified docker-compose.yaml and added:

version: '2'

services:
volumes:
      - /etc/hosts:/etc/hosts

However the host entry is not used this time either.
I cannot access a shell in traefik.

How do I go about using a host entry for traefik?

Thank you

OK So I am posting here because I spent a lot of effort trying to locate the necessary components to achieve this. Two things were needed in the docker-compose.yml to trigger traefik to check a local host entry:

  1. add a host entry to the traefik container /etc/hosts
    This part is really a docker config, however doing this alone wont achieve the desired outcome because traefik ignores /etc/hosts.
  2. Mount the nsswitch file from the docker host into the traefik container
    This part triggers traefik to check the local host file before DNS.

Docker compose:

version: '2'

services:
  proxy:
    ...
    extra_hosts:
      - 'www.something.com: 192.168.4.224'
    ...
    volumes:
      - /etc/nsswitch.conf:/etc/nsswitch.conf
...etc
1 Like