Windows 容器无法访问 Azure 容器实例?

Azure Container Instances no internet access for Windows Container?

我的 Windows Azure 容器实例中的容器似乎无法访问互联网。

如何从我的 Windows 容器访问互联网?

我必须在启动期间在容器中执行此 PowerShell 命令:

Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).IfIndex -ServerAddresses ('8.8.8.8')

然后我的容器能够成功解析 DNS 并访问互联网。

在 运行 中执行此脚本无效,因此我不得不以某种方式将它与我已经需要的 CMD 一起执行。我最终这样做了并且有效:

CMD ["powershell", "-Command", "\"Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).IfIndex -ServerAddresses ('8.8.8.8')\"; cd c:\app; .\my.exe ui"]

不要忘记转义 \"