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.

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 (
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; 
    Set-ExecutionPolicy Bypass -Scope Process -Force; 
    $env:chocolateyUseWindowsCompression = 'true'; 
    iex ((New-Object System.Net.WebClient).DownloadString(''))

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
The HTTP request to 'GET' has timed out after 100000ms.

I did the following tests:

  1. I can install chocolatey using both methods in the server, outside the container
  2. I can ping without issue within the Docker container.
  3. The same image was built in another server without problem.

Source: Docker Questions