title: Docker build cannot resolve DNS on Windows Server 2019
body: <h1>Problem</h1>
  <p>Running the following command:</p>
  <pre><code>docker build  --rm -f &quot;c:\Users\...\iotedgeModbus\Dockerfile.amd64.debug&quot; -t
  modbus:dev-amd64.debug &quot;c:\Users\...\iotedgeModbus&quot; ; if ($?) { iotedgehubdev start -d &quot;c:\Users\...\iotedgeModbus\config\deployment.debug.amd64.json&quot; -v }
  </code></pre>
  <p>outputs errors related to resolving DNS names:</p>
  <pre><code>Step 2/21 : RUN apt-get update &amp;&amp;     apt-get install -y --no-install-recommends unzip procps
  &amp;&amp;     rm -rf /var/lib/apt/lists/*
   ---&gt; Running in a389a7d1ff0d
  Err:1 http://security.debian.org/debian-security buster/updates InRelease
    Temporary failure resolving 'security.debian.org'
  Err:2 http://deb.debian.org/debian buster InRelease
    Temporary failure resolving 'deb.debian.org'
  Err:3 http://deb.debian.org/debian buster-updates InRelease
    Temporary failure resolving 'deb.debian.org'
  Reading package lists...
  </code></pre>
  <p>Full stack trace:</p>
  <pre><code>docker build  --rm -f &quot;c:\Users\...\iotedgeModbus\Dockerfile.amd64.debug&quot; -t
  modbus:dev-amd64.debug &quot;c:\Users\...\iotedgeModbus&quot; ; if ($?) { iotedgehubdev start -d &quot;c:\Users\...\iotedgeModbus\config\deployment.debug.amd64.json&quot; -v }
  Sending build context to Docker daemon  699.9kB
  Step 1/21 : FROM mcr.microsoft.com/dotnet/core/runtime:3.0.0-buster-slim AS base
   ---&gt; b525e32f0752
  Step 2/21 : RUN apt-get update &amp;&amp;     apt-get install -y --no-install-recommends unzip procps
  &amp;&amp;     rm -rf /var/lib/apt/lists/*
   ---&gt; Running in a389a7d1ff0d
  Err:1 http://security.debian.org/debian-security buster/updates InRelease
    Temporary failure resolving 'security.debian.org'
  Err:2 http://deb.debian.org/debian buster InRelease
    Temporary failure resolving 'deb.debian.org'
  Err:3 http://deb.debian.org/debian buster-updates InRelease
    Temporary failure resolving 'deb.debian.org'
  Reading package lists...
  W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Temporary failure resolving 'deb.debian.org'
  W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease
  Temporary failure resolving 'security.debian.org'
  W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Temporary failure resolving 'deb.debian.org'
  W: Some index files failed to download. They have been ignored, or old ones used instead.
  Reading package lists...
  Building dependency tree...
  Reading state information...
  E: Unable to locate package unzip
  E: Unable to locate package procps
  The command '/bin/sh -c apt-get update &amp;&amp;     apt-get install -y --no-install-recommends unzip procps &amp;&amp;     rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100
  </code></pre>
  <h1>Setup</h1>
  <p>I have the following configuration:</p>
  <ul>
  <li>Azure VM (Standard D2s v3 [2 vcpus, 8 GiB memory])</li>
  <li>VM OS is Windows Server 2019 Datacenter v1809</li>
  <li>Docker EE (v19.03.04 for both Server and Client engines)</li>
  <li>WSL installed and tested via <a href="https://computingforgeeks.com/run-linux-on-windows-server/" rel="nofollow noreferrer">this guide</a>.</li>
  <li>LCOW enabled, tested, and set as the default via <a href="https://bcthomas.com/2019/02/getting-started-with-linux-containers-on-windows-server-2019/" rel="nofollow noreferrer">this guide</a></li>
  <li>daemon.json file configured with DNS servers</li>
  <li>Host is connected to the internet</li>
  </ul>
  <h3>Background</h3>
  <p>I am trying to debug an issue that my container is experiencing in the production environment, so I want to run it on the production machine.</p>
  <h3>Docker configuration</h3>
  <p>Contents of <code>daemon.json</code> file:</p>
  <pre><code>{
      &quot;experimental&quot;: true,
      &quot;dns&quot;: [&quot;208.67.222.222&quot;, &quot;208.67.220.220&quot;],
      &quot;bridge&quot;: &quot;none&quot;
  }
  </code></pre>
  <p>This file is in &quot;C:\ProgramData\Docker\config&quot; as per <a href="https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon#configure-docker-with-a-configuration-file" rel="nofollow noreferrer">this documentation</a>.</p>
  <p>Running <code>docker info</code> outputs:</p>
  <pre><code>Client:
   Debug Mode: false
   Plugins:
    cluster: Manage Docker clusters (Docker Inc., v1.2.0)
  
  Server:
   Containers: 5
    Running: 0
    Paused: 0
    Stopped: 5
   Images: 3
   Server Version: 19.03.4
   Storage Driver: windowsfilter (windows) lcow (linux)
    Windows:
    LCOW:
   Logging Driver: json-file
   Plugins:
    Volume: local
    Network: ics internal l2bridge l2tunnel nat null overlay private transparent
    Log: awslogs etwlogs fluentd gcplogs gelf json-file local logentries splunk syslog
   Swarm: inactive
   Default Isolation: process
   Kernel Version: 10.0 17763 (17763.1.amd64fre.rs5_release.180914-1434)
   Operating System: Windows Server 2019 Datacenter Version 1809 (OS Build 17763.864)
   OSType: windows
   Architecture: x86_64
   CPUs: 2
   Total Memory: 8GiB
   Name: xxxxxxxx
   ID: GMKH:37MH:LDBL:AXQA:DYNK:342Y:A2AR:OLJP:WRJM:YQV2:4XZA:XJCR
   Docker Root Dir: C:\ProgramData\docker
   Debug Mode: false
   Registry: https://index.docker.io/v1/
   Labels:
   Experimental: true
   Insecure Registries:
    127.0.0.0/8
   Live Restore Enabled: false
  </code></pre>
  <p>Running <code>docker network ls</code> outputs:</p>
  <pre><code>NETWORK ID          NAME                DRIVER              SCOPE
  3c451e980ddd        nat                 nat                 local
  c2d54c8da069        none                null                local
  </code></pre>
  <p>Running <code>docker network inspect nat</code> outputs:</p>
  <pre><code>[
      {
          &quot;Name&quot;: &quot;nat&quot;,
          &quot;Id&quot;: &quot;3c451e980dddda1b46005caba457f56efb4aba610668c5d58f7c3cc839604347&quot;,
          &quot;Created&quot;: &quot;2019-11-12T22:07:47.6443712Z&quot;,
          &quot;Scope&quot;: &quot;local&quot;,
          &quot;Driver&quot;: &quot;nat&quot;,
          &quot;EnableIPv6&quot;: false,
          &quot;IPAM&quot;: {
              &quot;Driver&quot;: &quot;windows&quot;,
              &quot;Options&quot;: null,
              &quot;Config&quot;: [
                  {
                      &quot;Subnet&quot;: &quot;172.20.160.0/20&quot;,
                      &quot;Gateway&quot;: &quot;172.20.160.1&quot;
                  }
              ]
          },
          &quot;Internal&quot;: false,
          &quot;Attachable&quot;: false,
          &quot;Ingress&quot;: false,
          &quot;ConfigFrom&quot;: {
              &quot;Network&quot;: &quot;&quot;
          },
          &quot;ConfigOnly&quot;: false,
          &quot;Containers&quot;: {},
          &quot;Options&quot;: {
              &quot;com.docker.network.windowsshim.hnsid&quot;: &quot;8991C564-50DB-4AE0-9C75-7B117787CC7E&quot;,
              &quot;com.docker.network.windowsshim.networkname&quot;: &quot;nat&quot;
          },
          &quot;Labels&quot;: {}
      }
  ]
  </code></pre>
  <p>Contents of <code>Dockerfile.amd64.debug</code> are:</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/core/runtime:3.0.0-buster-slim AS base
  
  RUN apt-get update &amp;&amp; \
      apt-get install -y --no-install-recommends unzip procps &amp;&amp; \
      rm -rf /var/lib/apt/lists/*
  
  RUN useradd -ms /bin/bash moduleuser
  USER moduleuser
  RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg
  
  FROM mcr.microsoft.com/dotnet/core/sdk AS build-env
  WORKDIR /app
  
  COPY *.csproj ./
  RUN dotnet restore
  
  COPY . ./
  RUN dotnet publish -c Debug -o out
  
  FROM gcc:7 AS build-env-2
  WORKDIR /app
  
  # copy .c and .h file
  COPY *.c ./
  COPY *.h ./
  
  # build
  RUN gcc -shared -o libcomWrapper.so -fPIC comWrapper.c
  
  FROM base
  WORKDIR /app
  COPY --from=build-env /app/out ./
  COPY --from=build-env-2 /app/libcomWrapper.so /usr/lib/
  
  ENTRYPOINT [&quot;dotnet&quot;, &quot;iotedgeModbus.dll&quot;]
  </code></pre>
  <p>My <code>deployment.debug.template.json</code> file has the same structure as <a href="https://github.com/Azure/iot-edge-modbus/blob/master/iotedgeModbus/deployment.template.json" rel="nofollow noreferrer">this example</a>.</p>
  <h1>Attempted solutions</h1>
  <p>I have tried the following in an attempt to rectify the issue:</p>
  <ul>
  <li>Confirmed that the host can <code>ping</code> google.com, deb.debian.org, and security.debian.org.</li>
  <li>Confirmed that the host machine successfully returns <code>nslookup</code> results for google.com, deb.debian.org, and security.debian.org.</li>
  <li>Updated daemon.json file with DNS entries for Google DNS, OpenDNS, and host adapter DNS then restarted the docker service to test connectivity.</li>
  <li>Specified the adapter to use in the <code>docker build</code> command with the <code>--network</code> flag, I have tried both the nat and none networks.</li>
  <li>Setting the DNS use to Google DNS and OpenDNS servers on the vEthernet (nat) adapter on the host machine.</li>
  <li>Specifying the DNS servers to use with the <code>--dns</code> flag (seems only be available for dockerd rather than docker.</li>
  <li>Setting the <code>InterfaceMetric</code> of the adapter the host uses to connect to the internet to be lower than those of the other adapters, as per <a href="https://github.com/docker/for-win/issues/2760" rel="nofollow noreferrer">this comment</a>.</li>
  <li>Confirmed that host networking does not work for Docker EE on Windows Server as per <a href="https://docs.docker.com/network/host/" rel="nofollow noreferrer">the documentation</a>.</li>
  <li>Attempted to create a bridge network with <code>docker network create -d bridge mynetwork</code> but encountered: &quot;Error response from daemon: could not find plugin bridge in v1 plugin registry: plugin not found&quot;.</li>
  <li>Created a transparent network adapter using <code>docker network create -d transparent MyNetwork</code> but since <code>docker build</code> does not complete, I cannot attach it to a container.</li>
  </ul>