以前我们的应用程序在 .net 框架上运行,我们使用 powershell 通过运行以下命令将我们的证书安装到证书存储中:RUN powershell -NoProfile -Command \
$Secure_String_Pwd = ConvertTo-SecureString "ourverysecretpassword" -AsPlainText -Force ; \
Import-PfxCertificate -FilePath /cert.pfx -CertStoreLocation Cert:\LocalMachine\Root -Exportable -Password $Secure_String_Pwd
但是现在我们已经将我们的代码转移到了 .netcore,上面的命令在 dockerfile 中将不再起作用。
关于如何通过 dockerfile 将现有的 .pfx 证书安装到 docker 容器中的任何想法?
[编辑]
我试图在 Windows 上运行我的容器,这是完整的 dockerfile,也许只是我使用了错误的图像:
这是整个 docker 文件:
FROM microsoft/dotnet
COPY ./Web /app/
COPY cert.pfx /cert.pfx
RUN powershell -NoProfile -Command \
$Secure_String_Pwd = ConvertTo-SecureString "againourverysecretpassword" -
AsPlainText -Force ; \
Import-PfxCertificate -FilePath /cert.pfx -CertStoreLocation
Cert:\LocalMachine\Root -Exportable -Password $Secure_String_Pwd
WORKDIR /app
EXPOSE 5000
ENTRYPOINT ["dotnet", "myhost.dll"]
无论如何它在 run powershell 命令上失败,说:
'powershell' 未被识别为内部或外部命令,
可运行的程序或批处理文件。
最佳答案
您的 Docker 容器是否在 Linux 上运行?
我认为是的。那么你的基本图像应该是 microsoft/aspnetcore
,它基于 Ubuntu。
你应该在你的 DOCKERFILE
中添加这个:
COPY ca_bundle.crt /usr/local/share/ca-certificates/your_ca.crt
RUN update-ca-certificates
第一行将您的 CA 包复制到镜像中,第二行更新 CA 列表。
CA 包(签署您的证书的机构列表)可以从 PFX 中提取,只需谷歌即可。 This是我找到的第一个链接。
如果您的容器在 Windows 上运行,那么 Powershell 命令应该按原样工作(我不确定)
关于https - 在 dotnet core docker 容器中安装证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49153782/