Unable to create a dev certificate for an ASP.NET Core Web App in a Docker container Unable to create a dev certificate for an ASP.NET Core Web App in a Docker container docker docker

Unable to create a dev certificate for an ASP.NET Core Web App in a Docker container


I recently got this to work for my project. I cribbed a lot of it from the Visual Studio Docker Compose files that were generated.

There are several differences that I see in your compose syntax that might be contributing to your issue.

First, your environment variables - I'm not sure what version of compose you're using. I was using 3.7 and I was able to define the variables this way:

      ASPNETCORE_ENVIRONMENT: "Development"      ASPNETCORE_URLS: "https://+:443;http://+:80"      ASPNETCORE_HTTPS_PORT: "44371"

Notice that the main difference here is that I'm declaring my aspnetcore urls using a wild card character for the domain and declaring the port number directly after that https://+:443;http://+:80 as the internal port numbers

I was able to access the application exactly how I expected by https://localhost:44371.

I do still define ports in my compose file too, but I think the main thing here is that you need to tell aspnet core what the ports are via your ASPNETCORE_URLS environment variable. The ports declared in your compose file are informing your docker container, not your application.

So a compose file that may work for you would be the following:

apigateway.website.public:  environment:    ASPNETCORE_ENVIRONMENT: "Development"    ASPNETCORE_URLS: "https://+:443;http://+:80"    ASPNETCORE_HTTPS_PORT: "5001"  volumes:    - ${APPDATA}/Microsoft/UserSecrets/:/root/.microsoft/usersecrets:ro    - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro  ports:    - "5000:80"    - "5001:443"

I also added the :ro (read only) indicator on your volumes as that seems to be a best practice.