Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to access internet inside docker windows container

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'

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

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 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

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.

like image 303
Mad-D Avatar asked Jan 16 '20 09:01

Mad-D


People also ask

Can a Docker container access Internet?

First thing to check is run cat /etc/resolv. conf in the docker container. If it has an invalid DNS server, such as nameserver 127.0. x.x , then the container will not be able to resolve the domain names into ip addresses, so ping google.com will fail.

Does Docker use port 8080?

Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .

How do I add a network to an existing container?

If you want to add a container to a network after the container is already running, use the docker network connect subcommand. You can connect multiple containers to the same network. Once connected, the containers can communicate using only another container's IP address or name.


2 Answers

I have had the same problem and was able to resolve it setting the DNS.

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/engine/reference/commandline/dockerd/#daemon-dns-options

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/run/#network-settings

like image 123
flec Avatar answered Oct 08 '22 03:10

flec


I was struggling with a similar issue, and it was because I was connected to a VPN and hadn't enabled the setting "Allow local (LAN) access when using VPN (if configured)" in Cisco AnyConnect. Just in case anyone else is struggling with a similar issue.

like image 21
IBN Avatar answered Oct 08 '22 04:10

IBN