在dotnet核心docker容器中安装证书

M. *_*hof 6 https certificate pfx dockerfile

以前我们的应用程序在.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 Code Online (Sandbox Code Playgroud)

无论如何它在运行powershell命令时失败,说:'powershell'不被识别为内部或外部命令,可操作程序或批处理文件.

Mar*_*olo 10

你的Docker容器在Linux上运行吗?

我认为是的.然后你的基本图像应该是microsoft/aspnetcore,它基于Ubuntu.

你应该在你的DOCKERFILE:

COPY ca_bundle.crt /usr/local/share/ca-certificates/your_ca.crt
RUN update-ca-certificates
Run Code Online (Sandbox Code Playgroud)

第一行将CA捆绑包复制到映像中,第二行更新CA列表.

CA捆绑包(签署证书的权限列表)可以从PFX中提取,只需Google提取即可.是我找到的第一个链接.

如果您的容器在Windows上运行,那么Powershell命令应该按原样运行(我不确定)