Not able to access internet inside docker windows container
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
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.
Specifying network command can be used as a workaround. Works for both build
and run
docker build --network="Default Switch" .docker run --rm -it --network="Default Switch" mcr.microsoft.com/windows/servercore:ltsc2019
And the name is the one from here:
docker network lsNETWORK ID NAME DRIVER SCOPE79b90200b5ad Default Switch ics local07ffb031d4b7 nat nat local6682d6220de5 none null local
For some reason docker default (nat
) doesn't have internet connection.