如何在运行 .net Core 模板的 windows docker 容器和 windows 主机中安装开发证书?

use*_*465 5 ssl-certificate docker asp.net-core

我使用 Visual Studio 模板添加了 Docker 支持,并且用户机密具有证书的密码,并且用户机密和证书作为卷安装在docker-compose.override.yml

volumes:
      - ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro
      - ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
Run Code Online (Sandbox Code Playgroud)

我什至连接到容器以验证证书是否在 Https 文件夹中。由于某种原因没有安装它。运行该应用程序会引发一个错误,指出证书存储中不存在开发证书。我应该如何安装它?是否有我需要的设置以便它自动安装在容器中?

确切的错误信息:

System.InvalidOperationException: '无法配置 HTTPS 端点。未指定服务器证书,并且找不到默认的开发者证书。

我可以按照错误说明创建证书并将其添加到容器中:

dotnet dev-certs https
dotnet dev-certs https --trust
Run Code Online (Sandbox Code Playgroud)

但是 .net sdk 并未安装在最终容器中,只是安装在 .net 核心运行时中。

Sun*_*est 3

Not sure if this helps anyone but I was having this issue recently and found a way to correct the issue in my situation. It's not a permanent fix but just so I can develop locally for now.

In the docker-compose.override.yml file I changed the ASPNETCORE_ENVIRONMENT from Production to Development.

When I post to live, I will just need to remember to restore this.

在此输入图像描述

Note: I am new to docker so take it easy on me. Feel free to edit this answer anyone to improve.