无法访问Docker Windows容器内的Internet [英] Not able to access internet inside docker windows container
问题描述
我正在尝试使用docker windows容器构建映像.这是我的dockerfile
I am trying to build an image using docker windows container. Here is my dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as installer
RUN Invoke-WebRequest -URI 'www.google.com'
当我运行它时,它无法连接到google.com
When I run this it is failing to connect to google.com
Invoke-WebRequest : The remote name could not be resolved: 'www.google.com'
At line:1 char:73
我在公司网络上工作,我尝试使用设置代理
RUN netsh winhttp set proxy proxy-server="http://proxy.com:80" bypass-list="*.xyz.com"
并导入了注册表HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
I am working on a corporate network and I tried setting proxy using
RUN netsh winhttp set proxy proxy-server="http://proxy.com:80" bypass-list="*.xyz.com"
and also imported the registry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
我的容器中的ipconfig/all给出以下结果
ipconfig /all inside my container gives below result
Windows IP Configuration
Host Name . . . . . . . . . . . . : 0d5119fe9ce4
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Hyper-V Network Adapter
Physical Address. . . . . . . . . : 00-15-5D-B4-55-54
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fd80::a1f4:ab74:983:af83%4(Preferred)
IPv4 Address. . . . . . . . . . . : 172.xxx.xxx.xx(Preferred)
Subnet Mask . . . . . . . . . . . : 255.xxx.xxx.xx
Default Gateway . . . . . . . . . : 172.xxx.xxx.xx
DHCPv6 IAID . . . . . . . . . . . : 67114333
DHCPv6 Client DUID. . . . . . . . : 00-01-40-01-25-D1-CB-C4-00-15-5D-D4-A5-54
DNS Servers . . . . . . . . . . . : 172.xxx.xxx.xx
10.xxx.xxx.xx
NetBIOS over Tcpip. . . . . . . . : Disabled
我怀疑存在一些dns/防火墙问题或未正确设置代理.有人可以帮助我确定根本原因并解决此问题.
I suspect there is some dns/firewall issue or not setting proxy in a correct way. Can someone help me in identifying the root cause and fixing this issue.
推荐答案
我遇到了同样的问题,并且能够通过设置DNS来解决它.
I have had the same problem and was able to resolve it setting the DNS.
如果在构建期间进行呼叫,则可以在docker守护进程中进行设置. 在Docker Desktop中,转到设置">"Docker Engine",然后将以下内容添加到JSON配置中:
If you are making the call during build time you can set it in your docker daemon. In Docker Desktop go to "Settings" > "Docker Engine" and add the following to the JSON config:
"dns": ["1.1.1.1"]
https://docs.docker.com/引擎/参考/命令行/dockerd/#daemon-dns-options
如果在运行时遇到问题,则可以添加dns参数
If you are experiencing the problem during run time you can add the dns argument
--dns 1.1.1.1
https://docs.docker.com/engine/reference/运行/#network-settings
这篇关于无法访问Docker Windows容器内的Internet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!