[英]Docker - Windows Container Not Resolving Hosts
我使用 Docker 工具在 Visual Studio 中设置了两个新项目。 第一个是针对 Linux 容器运行的 asp.net 站点。 第二个是针对 Windows 容器运行的 asp.net 站点。
在前者中,我可以 ping 主机名(例如:google.com)并且它解析得很好。
但是,在运行 Windows 容器时,我不能做同样的事情。
我正在运行一个自定义网络,以便我可以确保容器在我想要的子网上启动:
docker network create --driver=nat --subnet=192.168.221.0/24
需要明确的是,我可以使用 IP ping 得很好,但是由于我想通过主机名连接到数据库,这在开发过程中并不是特别有用。
我只是想通了这一点。 需要在 Docker 桌面中“切换到 Windows 容器”。
1)。 关注: https : //docs.docker.com/machine/drivers/hyper-v/#example :
2)。 启动 hyper v(可能需要启用): https : //docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v
3)。 然后在 hyper v 中创建外部虚拟交换机。 选择您的 wifi 适配器。 (应该在打开或关闭 vpn 的情况下工作)。
4)。 重启。
5)。 我使用此图像,因为它必须与我的本地 windows windows 10 版本匹配:1809
docker pull mcr.microsoft.com/windows:1809 #takes an hour to finish
6). 启动容器并附加到新网络。
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"
显示:
"Containers": {
"b8c4ae07761fdf082602f836654013b8d83a717cce9156880a80c7542d855842": {
"Name": "win1809",
"EndpointID": "e84652fc93fd1fa2970c3bdcad513d8928fc35823a9f8cf0e638926b6091a60c",
"MacAddress": "00:15:5d:fb:77:dd",
"IPv4Address": "",
"IPv6Address": ""
7)。 连接到容器并 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.