Docker aspnetcore SSL Certificate


I’ve been using docker for aspnetcore applications and I had to add a 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 for local development, I skipped this step because I had my own 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
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/

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]


comments powered by Disqus