net 5 web api in docker with https

I followed this https://github.com/dotnet/dotnet-docker/blob/master/samples/run-aspnetcore-https-development.md
to get my net 5 web api application working in docker with Https. When I execute the run command :
docker run --rm -it -p 8080:80 -p 8081:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8081 -e ASPNETCORE_ENVIRONMENT=Development -v ${HOME}/.microsoft/usersecrets/:/root/.microsoft/usersecrets -v ${HOME}/.aspnet/https:/root/.aspnet/https/ weatherapi
everything works fine. I tried moving it to a docker compose file as shown below:

 version: '3.8'
services:
  weatherapi:
    build: 
      context: .
    ports:
      - '8080:80'
      - '8081:443'
    environment:
      - ASPNETCORE_URLS=https://+;http://+
      - ASPNETCORE_HTTPS_PORT="8081"
      - ASPNETCORE_ENVIRONMENT="Development"
    volumes: 
      - ${HOME}/.microsoft/usersecrets/:/root/.microsoft/usersecrets
      - ${HOME}/.aspnet/https:/root/.aspnet/https/

then I get this error even though am running the same command as the one above:

Microsoft.AspNetCore.Server.Kestrel[0]
weatherapi_1  |       Unable to start Kestrel.
weatherapi_1  |       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.
weatherapi_1  |       To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
weatherapi_1  |       For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
weatherapi_1  |          at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
weatherapi_1  |          at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
weatherapi_1  |          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
weatherapi_1  |          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context)
weatherapi_1  |          at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
weatherapi_1  |          at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
weatherapi_1  | Unhandled exception. 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.

Inspecting the container created by the first command I could see the environment variable and volumes paths is different to that of the container created by the docker-compose:

From command container:

 "HostConfig": {
                "Binds": [
                    "/Users/xxxx/.microsoft/usersecrets/:/root/.microsoft/usersecrets",
                    "/Users/xxxx/.aspnet/https:/root/.aspnet/https/"
},
"Env": [
                "ASPNETCORE_URLS=https://+;http://+",
                "ASPNETCORE_HTTPS_PORT=8081",
                "ASPNETCORE_ENVIRONMENT=Development",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_VERSION=5.0.0",
                "ASPNET_VERSION=5.0.0"
            ]

From docker-compose container:

"HostConfig": {
        "Binds": [
            "/Users/xxxx/.microsoft/usersecrets:/root/.microsoft/usersecrets:rw",
            "/Users/xxxx/.aspnet/https:/root/.aspnet/https:rw"
        ]
}
"Env": [
            "ASPNETCORE_URLS=https://+;http://+",
            "ASPNETCORE_HTTPS_PORT="8081"",
            "ASPNETCORE_ENVIRONMENT="Development"",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "DOTNET_RUNNING_IN_CONTAINER=true",
            "DOTNET_VERSION=5.0.0",
            "ASPNET_VERSION=5.0.0"
        ]

I spotted the difference in the url to user secrets: /usersecrets/:/root/ vs /usersecrets:/root.

I can’t get my app to start in the container with the same dev certificate the command is using despite the docker-compose file is exactly the same thing as the command and indicating the volumes and paths.

Source: Docker Questions