PowerShell的Invoke-WebRequest在Docker容器中不起作用

时间:2020-07-22 01:54:24

标签: powershell docker docker-container invoke-webrequest

在我的dockerfile中,有一行RUN PowerShell -ExecutionPolicy Unrestricted -File /approot/bin/DockerScripts/reqs.ps1

在reqs.ps1中,有一个invoke-webrequest命令,例如Invoke-WebRequest -Uri https://path/to/exe/ExeNeeded.exe -OutFile C:\ExeNeeded.exe

在计算机上运行docker build时,我在RUN PowerShell -ExecutionPolicy Unrestricted -File /approot/bin/DockerScripts/reqs.ps1步骤上收到错误消息

错误是:

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

我能够通过网络浏览器访问https://path/to/exe/ExeNeeded.exe,所以我知道该网址很好。我还临时关闭了计算机上的防火墙。我不确定为什么Invoke-WebRequest仍然无法正常工作。

1 个答案:

答案 0 :(得分:0)

对于 Windows 用户来说,它是众所周知的 issue#6453。构建图像时添加网络参数。

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