【发布时间】:2020-07-26 13:19:06
【问题描述】:
我在尝试调试指向 Visual Studio 中“生产”ASPNETCORE_ENVIRONMENT 的 docker 容器时遇到问题。 “开发”环境运行良好。我正在尝试针对生产容器进行调试,因为每个环境的不同 appsettings 文件存在问题。
这是我的错误:
无法配置 HTTPS 端点。未指定服务器证书,默认开发人员证书找不到或已过期。 要生成开发人员证书,请运行“dotnet dev-certs https”。要信任证书(仅限 Windows 和 macOS),请运行“dotnet dev-certs https --trust”。 有关配置 HTTPS 的更多信息,请参阅https://go.microsoft.com/fwlink/?linkid=848054。
我浏览了几篇文章,但在针对生产进行调试时似乎没有任何效果。当我从 launchSettings.json 中删除 https 时,该站点根本无法运行。
https://github.com/dotnet/dotnet-docker/blob/master/samples/host-aspnetcore-https.md
Unable to configure ASP.NET HTTPS endpoint in Windows docker container
环境:
Windows 10
Linux 容器
ASP.NET Core 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
}
Docker 文件
#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"]
【问题讨论】:
标签: asp.net visual-studio docker asp.net-core