[英]Docker - Windows Container Not Resolving Hosts
I have set up two new projects in Visual Studio using the Docker tooling.我使用 Docker 工具在 Visual Studio 中设置了两个新项目。 The first is a asp.net site running against a Linux container.第一个是针对 Linux 容器运行的 asp.net 站点。 The second is an asp.net site running against a Windows container.第二个是针对 Windows 容器运行的 asp.net 站点。
In the former, I can ping hostnames (ex: google.com) and it resolves just fine.在前者中,我可以 ping 主机名(例如:google.com)并且它解析得很好。
However, when running the windows container I cannot do the same thing.但是,在运行 Windows 容器时,我不能做同样的事情。
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.需要明确的是,我可以使用 IP ping 得很好,但是由于我想通过主机名连接到数据库,这在开发过程中并不是特别有用。
I just figured this out.我只是想通了这一点。 Requires "switching to windows container" in Docker Desktop.需要在 Docker 桌面中“切换到 Windows 容器”。
1). 1)。 Follow: https://docs.docker.com/machine/drivers/hyper-v/#example :关注: https : //docs.docker.com/machine/drivers/hyper-v/#example :
2). 2)。 Start hyper v (may need to enable): https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v启动 hyper v(可能需要启用): https : //docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v
3). 3)。 Then in hyper v create external virtual switch.然后在 hyper v 中创建外部虚拟交换机。 Select your wifi adapter.选择您的 wifi 适配器。 (should work with vpn on or off). (应该在打开或关闭 vpn 的情况下工作)。
4). 4)。 reboot.重启。
5). 5)。 I used this images as it has to match my local windows windows 10 version:1809我使用此图像,因为它必须与我的本地 windows windows 10 版本匹配:1809
docker pull mcr.microsoft.com/windows:1809 #takes an hour to finish
6). 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). 7)。 Connect to container and ping something:连接到容器并 ping 一些东西:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.