Search code examples
azuredockerdnswindows-server-2019docker-ee

Docker build cannot resolve DNS on Windows Server 2019


Problem

Running the following command:

docker build  --rm -f "c:\Users\...\iotedgeModbus\Dockerfile.amd64.debug" -t
modbus:dev-amd64.debug "c:\Users\...\iotedgeModbus" ; if ($?) { iotedgehubdev start -d "c:\Users\...\iotedgeModbus\config\deployment.debug.amd64.json" -v }

outputs errors related to resolving DNS names:

Step 2/21 : RUN apt-get update &&     apt-get install -y --no-install-recommends unzip procps
&&     rm -rf /var/lib/apt/lists/*
 ---> 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...

Full stack trace:

docker build  --rm -f "c:\Users\...\iotedgeModbus\Dockerfile.amd64.debug" -t
modbus:dev-amd64.debug "c:\Users\...\iotedgeModbus" ; if ($?) { iotedgehubdev start -d "c:\Users\...\iotedgeModbus\config\deployment.debug.amd64.json" -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
 ---> b525e32f0752
Step 2/21 : RUN apt-get update &&     apt-get install -y --no-install-recommends unzip procps
&&     rm -rf /var/lib/apt/lists/*
 ---> 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 &&     apt-get install -y --no-install-recommends unzip procps &&     rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100

Setup

I have the following configuration:

  • Azure VM (Standard D2s v3 [2 vcpus, 8 GiB memory])
  • VM OS is Windows Server 2019 Datacenter v1809
  • Docker EE (v19.03.04 for both Server and Client engines)
  • WSL installed and tested via this guide.
  • LCOW enabled, tested, and set as the default via this guide
  • daemon.json file configured with DNS servers
  • Host is connected to the internet

Background

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.

Docker configuration

Contents of daemon.json file:

{
    "experimental": true,
    "dns": ["208.67.222.222", "208.67.220.220"],
    "bridge": "none"
}

This file is in "C:\ProgramData\Docker\config" as per this documentation.

Running docker info outputs:

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

Running docker network ls outputs:

NETWORK ID          NAME                DRIVER              SCOPE
3c451e980ddd        nat                 nat                 local
c2d54c8da069        none                null                local

Running docker network inspect nat outputs:

[
    {
        "Name": "nat",
        "Id": "3c451e980dddda1b46005caba457f56efb4aba610668c5d58f7c3cc839604347",
        "Created": "2019-11-12T22:07:47.6443712Z",
        "Scope": "local",
        "Driver": "nat",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "windows",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.160.0/20",
                    "Gateway": "172.20.160.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.windowsshim.hnsid": "8991C564-50DB-4AE0-9C75-7B117787CC7E",
            "com.docker.network.windowsshim.networkname": "nat"
        },
        "Labels": {}
    }
]

Contents of Dockerfile.amd64.debug are:

FROM mcr.microsoft.com/dotnet/core/runtime:3.0.0-buster-slim AS base

RUN apt-get update && \
    apt-get install -y --no-install-recommends unzip procps && \
    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 ["dotnet", "iotedgeModbus.dll"]

My deployment.debug.template.json file has the same structure as this example.

Attempted solutions

I have tried the following in an attempt to rectify the issue:

  • Confirmed that the host can ping google.com, deb.debian.org, and security.debian.org.
  • Confirmed that the host machine successfully returns nslookup results for google.com, deb.debian.org, and security.debian.org.
  • Updated daemon.json file with DNS entries for Google DNS, OpenDNS, and host adapter DNS then restarted the docker service to test connectivity.
  • Specified the adapter to use in the docker build command with the --network flag, I have tried both the nat and none networks.
  • Setting the DNS use to Google DNS and OpenDNS servers on the vEthernet (nat) adapter on the host machine.
  • Specifying the DNS servers to use with the --dns flag (seems only be available for dockerd rather than docker.
  • Setting the InterfaceMetric of the adapter the host uses to connect to the internet to be lower than those of the other adapters, as per this comment.
  • Confirmed that host networking does not work for Docker EE on Windows Server as per the documentation.
  • Attempted to create a bridge network with docker network create -d bridge mynetwork but encountered: "Error response from daemon: could not find plugin bridge in v1 plugin registry: plugin not found".
  • Created a transparent network adapter using docker network create -d transparent MyNetwork but since docker build does not complete, I cannot attach it to a container.

Solution

  • Open the daemon configuration and add the DNS 8.8.8.8 in json format. Then restart the docker daemon. Apt get will work. The entry is

    {
        "dns": ["8.8.8.8"]
    }