无法在Windows上的Linux docker中配置ASP.NET HTTPS终结点

无法在Windows上的Linux docker中配置ASP.NET HTTPS终结点,asp.net,visual-studio,docker,asp.net-core,Asp.net,Visual Studio,Docker,Asp.net Core,我在Visual Studio中调试指向“生产”ASPNETCORE_环境的docker容器时遇到问题。“发展”环境运作良好。我正在尝试针对生产容器进行调试,因为每个环境的不同appsettings文件存在问题 这是我的错误: 无法配置HTTPS终结点。未指定服务器证书,无法找到默认的开发人员证书或证书已过期。 要生成开发人员证书,请运行“dotnet dev certs https”。要信任证书(仅限Windows和macOS),请运行“dotnet dev certs https--trus

我在Visual Studio中调试指向“生产”ASPNETCORE_环境的docker容器时遇到问题。“发展”环境运作良好。我正在尝试针对生产容器进行调试,因为每个环境的不同appsettings文件存在问题

这是我的错误:

无法配置HTTPS终结点。未指定服务器证书,无法找到默认的开发人员证书或证书已过期。 要生成开发人员证书,请运行“dotnet dev certs https”。要信任证书(仅限Windows和macOS),请运行“dotnet dev certs https--trust”。 有关配置HTTPS的更多信息,请参阅

我浏览了一些文章,但在针对生产环境进行调试时,似乎什么都不起作用。当我从launchSettings.json中删除https时,该站点根本不会运行

环境:

Windows 10
Linux容器
ASP.NET核心3.1

启动设置:

"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Production",
    "ASPNETCORE_URLS": "https://+:443;http://+:80",
  },
  "httpPort": 51934,
  "useSSL": true,
  "sslPort": 44349
}
DockerFile

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.2-bionic AS base
WORKDIR /app
EXPOSE 80
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y tzdata
RUN apt install -y --allow-unauthenticated \
    libc6-dev \
    libgdiplus \
    libx11-dev \
 && rm -rf /var/lib/apt/lists/*

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
WORKDIR /src
COPY src .
RUN dotnet restore "ExampleApp.Web/ExampleApp.Web.csproj"
COPY . .
WORKDIR "/src/ExampleApp.Web"
RUN dotnet dev-certs https --trust
RUN dotnet build "ExampleApp.Web.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ExampleApp.Web.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENV ASPNETCORE_ENVIRONMENT Production

ENTRYPOINT ["dotnet", "ExampleApp.Web.dll", "--environment=Production"]
一些选项

备选案文1: 在应用程序内部,像这样配置,它应该可以工作

WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseUrls(YourWebAppUrls)
                .UseKestrel()
                .ConfigureKestrel(options =>
                {
                    options.ListenAnyIP(51934);  // whatever your port
                })
                .UseIIS()
然后跑

dotnet dev-certs https -t

备选案文3:


备选案文4: 从中运行这些命令

使用Windows容器的Windows 生成证书并配置本地计算机:

dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p { password here }
dotnet dev-certs https --trust
运行核心配置为HTTPS的容器映像:

docker pull mcr.microsoft.com/dotnet/core/samples:aspnetapp
docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=\https\aspnetapp.pfx -v %USERPROFILE%\.aspnet\https:C:\https\ mcr.microsoft.com/dotnet/core/samples:aspnetapp

我的环境是docker。这些是针对本地机器上的IIS的。试试看,看看它们都有Linux机器的参考资料。不过开发是可行的。只有当环境指向生产的时候。嗯。。您是否有反向代理或其他与产品不同的产品。设置是什么样的。您是否在Digital Ocean上。我发布了一些来自ASP core 2.2的配置,试试看,当我在那里托管时,我列出的前几个选项都有效。当涉及到Windows容器或ASP托管时,Digital Ocean的支持很糟糕。
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p { password here }
dotnet dev-certs https --trust
docker pull mcr.microsoft.com/dotnet/core/samples:aspnetapp
docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=\https\aspnetapp.pfx -v %USERPROFILE%\.aspnet\https:C:\https\ mcr.microsoft.com/dotnet/core/samples:aspnetapp