title: HttpClient takes too much time when resolving Docker hostname locally
body: <p>We are using Docker on Windows Server 16 without 1709 update. We are running several .Net-Core projects inside Docker containers and just started to run UI tests on these containers using Selenium on .Net Standard. We run these tests locally, not inside containers. </p>
  
  <p>We are running the containers using docker-compose. The compose-file consists of multiple services  similar to following:</p>
  
  <pre><code>web:
   image: web
   build:
    context: ./Web/Web
    dockerfile: Dockerfile
   hostname: web
  
  simulator:
   image: simulator
   build:
    context: ./simulator/simulator
    dockerfile: Dockerfile
   hostname: simulator
  </code></pre>
  
  <p>In tests, we use simulator to simulate email activation and phone validation by posting requests and getting responses to appropriate controllers using REST. We tried using HttpClient and Refit for that. The tests were running too slow. So we looked for ways to improve the speed.</p>
  
  <p>Then we narrowed down the problem to the DNS.  When we use hostnames defined in the compose files, a simple <code>getAsync</code> request takes around 24 seconds to run. When we use the container IP address, it takes only a few milliseconds.</p>
  
  <p>To clarify, this is slow:</p>
  
  <pre><code>var client = new HttpClient ("http://Simulator");
  var result = client.GetAsync("controller/action");
  </code></pre>
  
  <p>And this is fast:</p>
  
  <pre><code>var client = new HttpClient ("http://172.32.40.1");  //containerIp
  var result = client.GetAsync("controller/action");
  </code></pre>
  
  <p>Furthermore, when we try to connect to google.com using <code>HttpClient</code> with a get request, it still takes only milliseconds. So the DNS issue only arises when we are resolving the IP of the docker containers. How can this problem be resolved? I am not expert in networking nor Docker, could you tell me where to look at? Is this another WS-not-1709 issue?</p>
  
  <p>Edit: Another case if I loop over this without disposing the HttpClient the first call is slow, but subsequent calls are fast again. </p>
  
  <pre><code>for (int i = 0; i&lt;SOME_LOOP_COUNT) {
      var client = new HttpClient ("http://simulator");   //slow when i == 0
      var result = client.GetAsync("controller/action");
  }
  </code></pre>