gpt4 book ai didi

docker - 如何在Windows docker镜像中安装.pfx证书

转载 作者:行者123 更新时间:2023-12-02 18:26:47 30 4
gpt4 key购买 nike

我有一个使用IdentityServer 4的.Net Core API,我正在尝试将该API运行到Docker Compose(Windows容器)中,但是由于以下异常而无法执行该操作:

Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

在Google上花费了数小时后,我发现了许多链接,其中首先需要安装证书,例如
dotnet dev-certs https --clean
dotnet dev-certs https --trust

**Docker - certificate not trusted**

1. Delete the C:\Users{USER}\AppData\Roaming\ASP.NET\Https folder.
2. Clean the solution. Delete the bin and obj folders.
3. Restart the Development tool. Visual Studio Code- 2019

在完成上述所有工作后都遇到相同的错误之后,我是否在做错了什么。

这是dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
user ContainerAdministrator

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src

COPY ../Certificate/idsrv3test.pfx .

COPY ["Tests-Identity/Tests-Identity.csproj", "Tests-Identity/"]
RUN dotnet restore "Tests-Identity/Tests-Identity.csproj"
COPY . .
WORKDIR "/src/Tests-Identity"
RUN dotnet build "Tests-Identity.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Tests-Identity.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Tests-Identity.dll"]

这是docker-compose.override.yml
version: '3.4'

services:
tests-identity:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80

ports:
- "5000:80"
- "5001:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
- ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro

最佳答案

穆内尔
根据我的理解,以下命令仅在您在IISEXPRESS上运行应用程序时才对您有帮助,但这绝对无济于事,但据我所知,您正在尝试在“Docker Compose”项目下运行API

dotnet dev-certs https --clean
dotnet dev-certs https --trust

因此,首先您需要在docker文件中删除管理容器用户
user ContainerAdministrator 

并删除这行
COPY ../Certificate/idsrv3test.pfx .

之后,在“X509Certificate2”中添加以下参数,该参数将在您的Certificate.cs文件中

enter image description here

请尝试此链接,它一定会对您有很大帮助
https://github.com/dotnet/dotnet-docker/issues/863

关于docker - 如何在Windows docker镜像中安装.pfx证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60451514/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com