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.
However, when running the windows container I cannot do the same thing.
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.
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