How to Fix Network Errors with Docker and Windows Containers

Last week I run into this annoying problem when I tired to run the .Net samples for Docker:

Step 7/23 : RUN dotnet restore
—> Running in ce2d8740cf2e
Restore completed in 389.74 ms for C:\app\dotnetapp\dotnetapp.csproj.
Restore completed in 220.85 ms for C:\app\utils\utils.csproj.
C:\Program Files\dotnet\sdk\2.2.402\NuGet.targets(123,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\dotnetapp.sln]
C:\Program Files\dotnet\sdk\2.2.402\NuGet.targets(123,5): error : No such host is known [C:\app\dotnetapp.sln]
The command ‘powershell -Command $ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’; dotnet restore’ returned a non-zero code: 1

Instead of a quick experiment with a build chain I spend the next two hours figuring out what was wrong with my installation. Googling for Docker and network error showed my many solutions for Linux or wrongly configured proxy servers, but nothing that solved my problem. Restarting Docker Desktop, restarting the Docker services via service manager, updating to the latest version and rebooting the whole machine did not work. The problem persisted.

I finally stumbled upon the suggestions of xtremeperf https://github.com/docker/for-win/issues/2760#issuecomment-430889666 in a long list of comments to a bug report on GitHub. As it turns out, Docker for Windows uses the network adapter with the lowest Id. When this adapter is deactivated, your container cannot connect to the internet.

To check if you have the same problem, open a PowerShell console and type this command to list all your network interfaces:

This should give you an output like this one:

Lowest Connector is disconnected

My interface ‘Ethernet’ was disconnected and therefore resulted in my network problems. To fix this, I moved my ‘Ethernet’ interface behind the first interface that was connected using this command:

To check if everything worked, I run the command to list the interfaces again. Now my adapter with the name ‘FreedomeVPNConnection’ is the lowest and has a ConnectionState of Connected:

Lowest Connector is connected

I went back to Docker and run the build command again. This time dotnet restore worked as expected:

Step 7/23 : RUN dotnet restore
—> Running in 8fc8b2e1bdf7
Restore completed in 261.33 ms for C:\app\dotnetapp\dotnetapp.csproj.
Restore completed in 217.62 ms for C:\app\utils\utils.csproj.
Restore completed in 3.6 sec for C:\app\tests\tests.csproj.
Removing intermediate container 8fc8b2e1bdf7
—> 0ffea5dbf780
Step 8/23 : COPY . .
—> eb169ea56442

I hope this post will help you to fix our networking errors in Docker (on Windows). Since I did this little change, I had no more networking problems.

18 thoughts on “How to Fix Network Errors with Docker and Windows Containers”

  1. HI Really!!!!!!!!!!!!!!!!!

    Tones of thanks for this post. I nearly spent 2 days until I found this solution.

    Thank god!!! no where explained this much detailed info.

    PS : For my this same strategy worked after I restarted my machine 🙂

    Reply
  2. Hi, I see you are using a VPN, which is listed as it’s own network adapter. I’m also using a VPN, but mine is not. Instead, when I connect, an adapter called Ethernet 2 is activated, despite me still beeing connected via WiFi.

    Moving either of them to the bottom of the list doesn’t solve the issue however. If WiFi is on the bottom, the error changes to a 404, and if Ethernet 2 is on the bottom, it still says “No such host is known.”

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.