.NET API docker-compose HTTPS/SSL problem

I recently started playing with Docker and I’ve run into a problem with running web API on HTTPS port in the developer environment.

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.

It turned out to be fairly easy to fix. Below 2 steps that you need to do to fix it.

Set Up Dev Certificates

First you need to set up your dev certificates with following commands:

dotnet dev-certs https --clean
dotnet dev-certs https --trust -ep $env:USERPROFILE.aspnet\https\aspnetapp.pfx -p {YOUR PASSWORD}

You’ll need to confirm two prompts.

Set Up Your Docker-Compose

Next step is to setup your docker-compose.yml file

version: '3.4'

services:
  webapi:
    image: ${DOCKER_REGISTRY-}webapi
    build:
      context: .
      dockerfile: Api/WebApi/Dockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_Kestrel__Certificates__Default__Password={YOUR PASSWORD}
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
    volumes:
      - ~/.aspnet/https:/https:ro
    ports:
      - "5007:443"

And you’re good to go.

Let's stay in touch!