Overview - Troubleshooting DNS Configuration Issue in Dockerfile for Windows-Based Builds
This workaround involves adding the netsh
command in the SHELL
statement of the Dockerfile. This fix resolves the DNS configuration problem and allows a successful build.
Error:
Exception calling "DownloadString" with "1" argument(s): "The remote name
could not be resolved: 'chocolatey.org'"
At line:1 char:322
+ ... -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE
xception
+ FullyQualifiedErrorId : WebException
Solution
To resolve the DNS configuration issue in your Dockerfile, please follow the steps outlined below:
Step 1: Update the Dockerfile
Add the netsh
command to your Dockerfile within the SHELL
statement, as shown below:
FROM mcr.microsoft.com/dotnet/framework/wcf:4.8
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue'; netsh interface ipv4 set dnsserver 17 static address=8.8.8.8 register=primary;"]
RUN powershell Set-ExecutionPolicy Bypass -Scope Process -Force; $env:chocolateyUseWindowsCompression = 'true'; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); choco install awscli urlrewrite vcredist-all -y
For example:
Update your CircleCI configuration file (e.g., .circleci/config.yml
) with the following content:
version: 2.1
jobs:
build:
machine:
image: windows-server-2019-vs2019:2022.08.1
resource_class: windows.large
steps:
- run: |
tee Dockerfile \<<EOD
FROM mcr.microsoft.com/dotnet/framework/wcf:4.8
SHELL ["powershell", "-Command", "\$ErrorActionPreference = 'Stop'; \$ProgressPreference = 'Continue'; \$verbosePreference='Continue'; netsh interface ipv4 set dnsserver 17 static address=8.8.8.8 register=primary;"]
RUN powershell Set-ExecutionPolicy Bypass -Scope Process -Force; \$env:chocolateyUseWindowsCompression = 'true'; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); choco install awscli urlrewrite vcredist-all -y
EOD
- run: docker build .
Conclusion
By incorporating the netsh command within your CircleCI configuration accordingly, you can resolve the DNS configuration issue encountered during Windows-based builds. This fix ensures that your containers build successfully without DNS-related errors.
If you have any further questions or encounter any difficulties during the process, please don't hesitate to reach out to our support team. We are always ready to assist you and ensure a seamless experience with your CircleCI builds.
Comments
Article is closed for comments.