Connection error to external sites from a Docker container on Windows Server

I cannot connect to internet sites from a Docker container on Windows Server. The container runs a command to download and execute a script, but it fails due to a DNS error.

Example Dockerfile:

		
FROM windows/servercore

SHELL ["Powershell"]

ENV UseCompression false; RUN iex ((new-object net.webclient).DownloadString('https://example.com/install.ps1'));

When running this, I get the following error:

		
Exception calling "DownloadString" with "1" argument(s): "The remote name could not be resolved: 'example.com'"

The container cannot access external DNS servers.
How can I fix this?

Jan Weber

7 months ago

3 answers

136 views

Rating

03
Answer

Answers

Anna Schmidt

6 months ago

Rating

00

Alternatively, try resetting the network settings by switching the container's network adapter from NAT to bridge mode and back. This can sometimes resolve connectivity issues.

Reply

José Sousa

7 months ago

Rating

00

You can add DNS servers directly in the daemon.json file, for example:

		
{ "dns": ["192.0.2.2", "8.8.8.8"] }

Check the DNS on the host by running:

		
ipconfig /all

After saving changes in daemon.json, restart Docker and test access to external sites.

Reply

Daniel Karlsson

7 months ago

Rating

00

The issue might be that the Docker container is using the DNS server configured for the NAT network interface. Try adding the --dns parameter with the DNS server's IP to specify which DNS to use for Docker.

Example:

		
docker run --dns 8.8.8.8 -it windows/servercore

Or add a DNS entry in the daemon.json file:

		
{ "dns": ["8.8.8.8"] }

Restart Docker to apply the changes.

Reply