bubu
bubu

Reputation: 179

PowerShell's Invoke-WebRequest not working within a Docker Container

In my dockerfile I have a line RUN PowerShell -ExecutionPolicy Unrestricted -File /approot/bin/DockerScripts/reqs.ps1

Within reqs.ps1 there is an invoke-webrequest command like so, Invoke-WebRequest -Uri https://path/to/exe/ExeNeeded.exe -OutFile C:\ExeNeeded.exe

When I run docker build on my computer I get an error on the RUN PowerShell -ExecutionPolicy Unrestricted -File /approot/bin/DockerScripts/reqs.ps1 step

The error is:

Invoke-WebRequest : The remote name could not be resolved:
https://path/to/exe/ExeNeeded.exe
At C:\approot\bin\DockerScripts\reqs.ps1:5 char:1
+ Invoke-WebRequest -Uri https://path/to/exe/ExeNeeded.exe
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt
   pWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
   ll.Commands.InvokeWebRequestCommand

I am able to access https://path/to/exe/ExeNeeded.exe through my web browser, so I know the url is good. I also temporarily turned off the firewall on my computer. I'm not sure why Invoke-WebRequest is still not working.

Upvotes: 1

Views: 4292

Answers (1)

Trinitron
Trinitron

Reputation: 384

It is known issue#6453 for windows users. Add network parameter when building the image.

docker build -t myProject . --network "Default Switch"

Upvotes: 2

Related Questions