我在 Windows Server 2016 主机上运行 Windows docker 容器,运行默认配置。
当使用命令运行 docker 容器时:
docker run -it microsoft/windowsservercore powershell
当我运行命令时:
ping <hostIPAddress>
只是说请求超时。 我已经检查过我可以 ping 通 8.8.8.8 和 google.com 等...甚至同一子网上的其他机器。我唯一无法 ping 通的是主机。
我已将“--dns”添加到“docker run”命令,但这只允许我通过主机名而不是 IP ping 主机。
有没有其他人看到这个问题并有解决方案?
最佳答案
我找到了一个解决方法(我不愿意称之为解决方案):
Windows Container Network Drivers :创建一个“透明”网络:
docker network create -d transparent trans
将容器附加到这个网络
docker run --network=trans ...
重要:请注意,使用此网络,您的容器需要从主机子网获取 IP 地址,并直接暴露给它。
可能相关(这是关于从主机访问容器):
根据 https://github.com/Microsoft/Virtualization-Documentation/issues/253#issuecomment-217975932 (JMesser81):
This is a known limitation in our Windows NAT implementation (WinNAT) that you cannot access the external port in a static port mapping directly from the container (NAT) host.
关于Windows docker 容器无法 ping 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43074576/