I have a .net core 3 app running locally/development just fine, both on its own and when run in a linux container. I then take the app and have it built into a docker image inside azure pipelines. The image is loaded to azure container registry.
Finally, I have an Azure Web APP for Containers (Linux) that uses the image to run.
Locally I have the docker-compose file set up like this:
environment:
- "ASPNETCORE_ENVIRONMENT=Development"
...
- "ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx"
- "ASPNETCORE_Kestrel__Certificates__Default__Password=Your_password123"
volumes:
- ~/.aspnet/https:/https:ro
For production I have the following:
environment:
- UseInMemoryDatabase=false
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_Kestrel__Certificates__Default__Path=/security/mycert.pfx
- "ASPNETCORE_Kestrel__Certificates__Default__Password=Your_password123"
ports:
- "5000:5000"
- "5001:5001"
volumes:
- fsmount001: /security:/security
- /var/ssl/private:/https
I loaded "mycert" into the azure portal and added its thumbprint to the App's configuration settings under WEBSITE_LOAD_CERTIFICATES
I used Open SSL to create the mycert file and I can use it locally and kestral will use it, but with a warning.
THE PROBLEM
When I run the app with this image I get the following error in the docker logs:
System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date ... at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
I have tried a lot of variations of loading certs and can not get any of them to work. This is an issue that only happens in production.
I also have tried:
- Purchased an Azure App Certificate and used the thumbprint.p12 file like:
- ASPNETCORE_Kestrel__Certificates__Default__Path=/var/ssl/private/<thumbprint>.p12
- ASPNETCORE_Kestrel__Certificates__Default__Password=""
I used no password because when you buy a cert there is no password set
Downloaded the purchased App Cert and used open ssl to create a password linked .pfk file and uploaded that as another private key
Use azure file mount and upload my dev cert files and reference them from the file mount like:
- ASPNETCORE_Kestrel__Certificates__Default__Path=/security/mycert.com.pfx
- ASPNETCORE_Kestrel__Certificates__Default__Password="Your_password123"
volumes:
- fsmount001: /security:/security
EDIT 1: Full docker-compose and azure file setup
There is a security folder with the mycert.pfx file inside it
- Here is how I set up the file mount in my azure app service configuration:
I set the mount path to be the security folder in my file share
- Here is the full docker compose file:
services:
webui:
image: ${DOCKER_REGISTRY-}webui
build:
context: .
dockerfile: src/WebUI/Dockerfile
environment:
- UseInMemoryDatabase=false
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=https://+:443;http://+:80
- "ConnectionStrings__DefaultConnection=****"
- ASPNETCORE_Kestrel__Certificates__Default__Path=/secure/mycert.pfx
- ASPNETCORE_Kestrel__Certificates__Default__Password="Your_password123"
ports:
- "5000:5000"
- "5001:5001"
volumes:
- fsmount001: /secure
- ~/var/ssl/private:/https
restart: always
volumes:
fsmount001:
driver: azure_file
driver_opts:
share_name: st-*****tus
storage_account_name: st********001
EDIT 2: DOCKERFILE
for further context you can find my dockerfile below
please note that I am using the open source application template/framework cleanarchiecture. You can see that I am trying to use the docker pull request for the repo as the base code. My goal is to "dockerize" this base framework in azure ci/cd pipeline and deploy it to azure web app for containers (linux)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000 5001 2222
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
WORKDIR /src
COPY ["src/WebUI/WebUI.csproj", "src/WebUI/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]
Can someone help me figure out how to set a certificate for kestral inside a Linux container?
thanks in advance