首页 > 解决方案 > docker 无法使用 https 导航到网站

问题描述

我有以下琐碎的 docker 文件:

FROM mcr.microsoft.com/windows/servercore:ltsc2019

WORKDIR /azp

COPY test.ps1 .

CMD powershell .\test.ps1

其中 test.ps1 是:

C:\test> cat .\test.ps1
curl https://cnn.com -UseBasicParsing

该脚本可以在我的机器上正常运行,但不能在 docker 容器中运行:

C:\test> docker build -t test:latest .
Sending build context to Docker daemon  75.26kB
Step 1/4 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
 ---> 782a75e44953
Step 2/4 : WORKDIR /azp
 ---> Using cache
 ---> b43270631602
Step 3/4 : COPY test.ps1 .
 ---> Using cache
 ---> 10cfc66cff37
Step 4/4 : CMD powershell .\test.ps1
 ---> Using cache
 ---> 187be18c5495
Successfully built 187be18c5495
Successfully tagged test:latest
C:\test> docker run test
curl : The underlying connection was closed: Could not establish trust
relationship for the SSL/TLS secure channel.
At C:\azp\test.ps1:1 char:1
+ curl https://cnn.com -UseBasicParsing
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt
   pWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
   ll.Commands.InvokeWebRequestCommand

请注意,将https://cnn.com( https )替换为http://google.com( http ) 是有效的,因此这显然与 https 有关。

我错过了什么?

附言

我正在使用 Windows 10,最新的 docker 切换为使用 Windows 容器。

标签: windowsdocker

解决方案


看起来您的容器无法验证 TLS 服务器证书。容器中可能缺少 CA 证书(可能它们在 Windows 中有不同的技术术语)。

你可以:

  • -SkipCertificateCheck(可从 PowerShell V6.0+ 获得),因此将跳过 TLS 证书验证 - 开发的好选择,但会部分牺牲安全性
  • “在容器中装载 Windows 主机证书存储” - Docker 论坛

推荐阅读