windows - 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 容器。
解决方案
看起来您的容器无法验证 TLS 服务器证书。容器中可能缺少 CA 证书(可能它们在 Windows 中有不同的技术术语)。
你可以:
-SkipCertificateCheck
(可从 PowerShell V6.0+ 获得),因此将跳过 TLS 证书验证 - 开发的好选择,但会部分牺牲安全性- “在容器中装载 Windows 主机证书存储” - Docker 论坛
推荐阅读
- reactjs - dispatch 不是函数错误
- azure - 为容器部署 Azure Web App 时出错
- go - 在 Golang 中执行 SQL Plus 命令
- python - 我应该如何解决这个 DeprecationWarning?
- wpf - 在 wpf 中的图像上绘制动态定位的叠加层
- android - Android webview播放时黑屏
- mysql - 如何在创建的字段上创建累积的 MySQL 查询?
- java - 访问 Google Sheets API 时出现 IllegalArgumentException
- python - Pandas ValueError:传递值的形状为 (6, 3),索引暗示 (6, 4)
- node.js - GoDaddy cpanel 上的 Node.JS 无法正常工作