3

I have set up two new projects in Visual Studio using the Docker tooling. The first is a asp.net site running against a Linux container. The second is an asp.net site running against a Windows container.

In the former, I can ping hostnames (ex: google.com) and it resolves just fine.

pinging from linux container

However, when running the windows container I cannot do the same thing.

windows network details and pinging from windows container

I am running a custom network so that I can ensure the container starts up on the subnet I want:

docker network create --driver=nat --subnet=192.168.221.0/24

To be clear, I can ping just fine by using an IP but since I want to connect to a database via hostname, this isn't especially helpful during development.

Killnine
  • 5,728
  • 8
  • 39
  • 66
  • Ever figure this out? – Kierk Sep 23 '20 at 12:33
  • Unfortunately, no. I ended up only supporting Linux-based containers. I am on an enterprise system with a proxy and using a VPN so there's a lot of other things that could be possibly causing issues. Though it's very frustrating to not have found a solution. – Killnine Sep 23 '20 at 13:10
  • I just got my windows container to work. Will provide answer – Kierk Sep 23 '20 at 13:31

1 Answers1

2

I just figured this out. Requires "switching to windows container" in Docker Desktop.

1). Follow: https://docs.docker.com/machine/drivers/hyper-v/#example:

2). Start hyper v (may need to enable): https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v

3). Then in hyper v create external virtual switch. Select your wifi adapter. (should work with vpn on or off).

4). reboot.

5). I used this images as it has to match my local windows windows 10 version:1809

docker pull mcr.microsoft.com/windows:1809   #takes an hour to finish

6). Start container and attach to new network.

docker run -dit --name win1809 mcr.microsoft.com/windows:1809 powershell
docker network ls
docker network connect "John Windows Container Switch" win1809
docker network inspect "John Windows Container Switch"

shows:

        "Containers": {
            "b8c4ae07761fdf082602f836654013b8d83a717cce9156880a80c7542d855842": {
                "Name": "win1809",
                "EndpointID": "e84652fc93fd1fa2970c3bdcad513d8928fc35823a9f8cf0e638926b6091a60c",
                "MacAddress": "00:15:5d:fb:77:dd",
                "IPv4Address": "",
                "IPv6Address": ""

7). Connect to container and ping something:

docker exec -it win1809 powershell
ping www.google.com

Pinging www.google.com [172.217.10.36] with 32 bytes of data:
Reply from 172.217.10.36: bytes=32 time=19ms TTL=118
Reply from 172.217.10.36: bytes=32 time=18ms TTL=118
Reply from 172.217.10.36: bytes=32 time=18ms TTL=118
Reply from 172.217.10.36: bytes=32 time=14ms TTL=118
Kierk
  • 476
  • 6
  • 23
  • 1
    ill accept this as an answer given it seems fairly plausible. I don't have any windows containers to test with currently so can't validate independently. But seems reasonable. Ill try and test later. – Killnine Sep 23 '20 at 13:48