I'm having issues trying to debug a docker container pointed at the "Production" ASPNETCORE_ENVIRONMENT in Visual Studio. The "Development" environment works fine. I'm trying to debug against a production container because we are having issues with the different appsettings file per environment.
This is my error:
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.
I've looked through a few articles but nothing seems to work when debugging against production. When I remove https from the launchSettings.json the site doesn't run at all.
https://github.com/dotnet/dotnet-docker/blob/master/samples/host-aspnetcore-https.md
Unable to configure ASP.NET HTTPS endpoint in Windows docker container
Environment:
Windows 10
Linux Containers
ASP.NET Core 3.1
launchSettings:
"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"]