I’ve been using docker for aspnetcore applications and I had to add an SSL certificate to one of them, as always Windows is doing things more complicated than it should since I faced a few issues, anyway, here is what after building the image.
Microsoft is using this sample on their docs:
Generate the certificate (This will apply to local development, I skipped this step because I had my certificate).
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p { password here }
dotnet dev-certs https --trust
Run the container with it
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 ${HOME}/.aspnet/https:/https/ mcr.microsoft.com/dotnet/core/samples:aspnetapp
Since I was using it on a Windows Server, I was facing some permissions issues which you can find more details here
Basically, I have to add the following parameter: -u ContainerAdministrator because: In Nano Server versions after 2016 the default user is the ContainerUser versus the ContainerAdministrator. If you run your 1803 image with the ContainerAdministrator.
So, since this is how I ended up running it:
docker run -d -u ContainerAdministrator -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=443 -e ASPNETCORE_Kestrel__Certificates__Default__Password="ssl-password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=\https\ssl-certificate.pfx -v C:\path-to-ssl\ssl\https:C:\https\ [image-name] [container-name]
REFERENCES:
https://docs.microsoft.com/en-us/aspnet/core/security/docker-https?view=aspnetcore-3.1