PowerShell 的 Invoke-WebRequest 在 Docker 容器中不起作用 (PowerShell's Invoke-WebRequest not working within a Docker Container)


問題描述

PowerShell 的 Invoke‑WebRequest 在 Docker 容器中不起作用 (PowerShell's Invoke‑WebRequest not working within a Docker Container)

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

在 reqs.ps1 中有一個調用‑像這樣的 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
      </code></pre>

      我可以通過我的網絡瀏覽器訪問https://path/to/exe/ExeNeeded.exe,所以我知道這個網址很好。我還暫時關閉了計算機上的防火牆。我不知道為什麼


參考解法

方法 1:

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

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

(by bubuTrinitron)

參考文件

  1. PowerShell's Invoke‑WebRequest not working within a Docker Container (CC BY‑SA 2.5/3.0/4.0)

#powershell #invoke-webrequest #docker-container #docker






相關問題

玩弄 C# 加密 (Playing around with C# encryption)

查找具有特定 startname 的特定服務 (Finding specific services with specific startname)

試圖從事件日誌中獲取數據到電子郵件中的 html (Trying to get data from event logs into html in email)

如何通過powershell獲取請求的authtoken (How to obtain authtoken for request via powershell)

如何在錯誤時繼續使用 &$var 調用可執行文件 (How to continue on error a call to an executable using &$var)

在同一範圍內從 c# 調用多個 powershell 命令 (Invoke multiple powershell commands from c# on the same scope)

如何在 Powershell 二進制模塊(.Net Standard 和 Nuget)中處理公共和私有依賴項和打包 (How to handle public and private dependencies and packaging in Powershell binary module (.Net Standard & Nuget))

如何使用參數(描述空白)獲取廣告中的所有 OU - 沒有描述? (How to get all OU in Ad with parameter (description blank ) - without description?)

遠程服務器返回錯誤:(400) 錯誤請求。在 C:\Program Files\WindowsPowerShell\Modules\CosmosDB\3.1.0.293\CosmosDB.psm1 (The remote server returned an error: (400) Bad Request. At C:\Program Files\WindowsPowerShell\Modules\CosmosDB\3.1.0.293\CosmosDB.psm1)

Powershell 檢查文件類型 (Powershell check file type)

服務器待重啟 (Server Pending Reboot)

PowerShell 的 Invoke-WebRequest 在 Docker 容器中不起作用 (PowerShell's Invoke-WebRequest not working within a Docker Container)







留言討論