title: Docker container internal vs external dns resolution issue using Traefik
body: <p>Docker 18.06.1-ce, traefik 1.7.3, dnsmasq, Mac 10.14</p>
  
  <p>I have docker-compose setup with Traefik and need to access several services from inside the docker network/containers and externally. </p>
  
  <p>On a linux box (with Let'sEncrypt and http redirected to https), everything works using the same FQDN for both docker container internal and external access, and I don't have to use the service names.</p>
  
  <p>When I run <code>curl http://belapi.dev.biodati.test</code> from inside the pipeline container using docker-compose exec belapi /bin/bash I get the following error (and I don't see it showing up in the Traefik access logs):</p>
  
  <pre><code>api@407cf7105aee:/app$ curl http://belapi.dev.biodati.test/status
  curl: (7) Failed to connect to belapi.dev.biodati.test port 80: Connection refused
  </code></pre>
  
  <p>This works fine (using the servicename):</p>
  
  <pre><code>curl http://belapi:8000/status
  </code></pre>
  
  <p>I can also run the following fine from a bash shell on my Mac outside the docker containers (and I see it hitting the Traefik access logs):</p>
  
  <pre><code>curl http://belapi.dev.biodati.test/status
  </code></pre>
  
  <p>I have dnsmasq setup to forward all *.test domains to 127.0.0.1.</p>
  
  <p>From inside the pipeline container:</p>
  
  <pre><code>dig belapi.dev.biodati.test
  
  ;; QUESTION SECTION:
  ;belapi.dev.biodati.test.   IN  A
  
  ;; ANSWER SECTION:
  belapi.dev.biodati.test. 7  IN  A   127.0.0.1
  </code></pre>
  
  <p>My docker-compose file:</p>
  
  <pre><code>networks:
    biodati:
      external: true
  
  services:
  
    pipeline:
      container_name: pipeline
      image: biodati/bel_pipeline:dev
      networks:
        biodati:
  
    traefik:
      image: traefik:1.7
      container_name: traefik
      ports:
        - "80:80"
        - "443:443"
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
        - ./conf/traefik.toml:/traefik.toml
        - ./logs:/logs
      networks:
        biodati:
      labels:
        - traefik.enable=true
        - traefik.backend=traefik
        - traefik.frontend.rule=Host:traefik.${BS_HOST_NAME:?err}
        - traefik.port=8080
        - traefik.docker.network=biodati
  
    # BEL API - core requirement
    belapi:
      container_name: belapi
      image: belbio/bel_api:localdev
      networks:
        biodati:
      labels:
        - traefik.enable=true
        - traefik.backend=belapi
        - traefik.frontend.rule=Host:belapi.${BS_HOST_NAME:?err};
        - traefik.port=8000
        - traefik.docker.network=biodati
  </code></pre>