Docker for Windows

Following on from my previous post outlining some General Docker Tips and Tricks this post covers some of the networking issues I have experienced and how I managed to fix this. I imagine this post will be a work in progress as I definitely have a lot still to learn when it comes to Docker networks.

There are some very useful guides to networking, including the general Docker networking documentation and the Docker for Windows specific Microsoft networking documentation.

If you are having networking issues, one way to inspect the Docker network is to run the following.

docker network inspect nat

There is also another handy script to clean up the container networking here

Using this script you can try resetting your container network stack with the -Cleanup switch or going further, force deletion of switches with the -ForceDeleteAllSwitches flag. Restarting Docker will then recreate all required settings which worked for me.

.\WindowsContainerNetworking-LoggingAndCleanupAide.ps1 -Cleanup -ForceDeleteAllSwitches

Unable to access the internet from a container

When developing an application that communicates amongst internal nodes and doesn’t need external access, this may not crop up. But if you need to call out to external services or if in my case if you are building an image and want to download and install files you may run into problems.

For me the problem was due to DNS within the container. To verify this, you can try the following command:

docker run --rm -ti microsoft/nanoserver ping google.com

This will start a new Windows container running nanoserver and run the ping command against Google. If you are having DNS issues, this will fail saying that google.com can’t be resolved.

To check that the container has connectivity, but the issue is due to DNS lookup, try pinging the Google DNS server using an IP address:

docker run --rm -ti microsoft/nanoserver ping 8.8.8.8

If this works and you get a response then like me you have a DNS issue. Thanks to this blog post for providing the answer.

Setting a DNS server address

To fix this issue you just need to tell Docker to use a specific DNS server. You can do this by going to the Docker settings, clicking the Daemon tab and then switching to advanced mode. You will then be able to edit the settings and enter an additional dns entry as an array of DNS servers. It is a good idea to check your machine using ipconfig /all and add the local DNS server as the first entry, you can then add others such as the Google DNS server on 8.8.8.8

{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": true,
  "dns": [
    "8.8.8.8"
  ]
}

Docker Settings

Now try the first command again and it should resolve the domain name this time.