Windows docker build. Network issues

  chocolatey, docker, nuget, windows

I’m building a Windows image, and I’m trying to install chocolatey. However in the install step for Chocolatey I am getting a download timeout trying to run the command.

Here the Dockerfile, trying to install chocolatey with powershell.

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-20210112-windowsservercore-ltsc2019
SHELL ["powershell", "-Command"]
RUN New-Item -ItemType directory -Path $Env:SOME_USER_HOME; 
    #Override the action to take in response to a non-terminanting error occurring, to STOP. 
    $ErrorActionPreference = 'Stop';
#Install chocolatey (https://chocolatey.org/docs/installation)
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; 
    Set-ExecutionPolicy Bypass -Scope Process -Force; 
    $env:chocolateyUseWindowsCompression = 'true'; 
    iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

The error:

Exception calling "DownloadString" with "1" argument(s): "The operation has timed out" At line:1 char:179 + ... n = 'true'; iex((New-ObjectSystem.Net.WebClient).DownloadString('ht...

Then I tried to install chocolatey using Nuget CLI

RUN nuget install chocolatey

But I received a similiar error.

Unable to load the service index for source https://api.nuget.org/v3/index.json.
The HTTP request to 'GET https://api.nuget.org/v3/index.json' has timed out after 100000ms.

I did the following tests:

  1. I can install chocolatey using both methods in the server, outside the container https://docs.chocolatey.org/en-us/choco/setup#install-using-nuget-package-manager
  2. I can ping chocolatey.org without issue within the Docker container.
  3. The same image was built in another server without problem.

Source: Docker Questions

LEAVE A COMMENT