我有一个使用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
Muneer根据我的理解,以下命令仅在您在IISEXPRESS下运行应用程序时才对您有帮助,但这绝对不会对您有帮助,但据我所知,您正在尝试在“ Docker Compose”项目下运行API
dotnet dev-certs https --clean
dotnet dev-certs https --trust
因此,首先您需要在Docker文件中删除管理容器用户
user ContainerAdministrator
并且也删除此行
COPY ../Certificate/idsrv3test.pfx .
之后添加以下参数“ X509Certificate2”,该参数将在您的Certificate.cs文件中
请尝试此链接,它一定会对您有很大帮助https://github.com/dotnet/dotnet-docker/issues/863