2

I configured my Asp.Net core project with compose-up.

And the secton for web is below:

    server:
        container_name: 'server'
        image: 'mcr.microsoft.com/dotnet/aspnet:5.0'
    #    restart: always
        working_dir: '/app'
        ports: 
            - "8886:80"
            - "8887:443"
        volumes: 
            - 'C:/Users/xx/Docker/meekou-server/:/app'
            - 'C:\Users\xx\Docker\meekou-certificates\https:/https/'
        environment: 
            - ASPNETCORE_ENVIRONMENT=Production
            - ASPNETCORE_URLS=http://+:80
            - ASPNETCORE_Kestrel__Certificates__Default__Password=test
            - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
        entrypoint: 
            ["dotnet", "xx.Web.Host.dll"]           
        depends_on: 
            - meekou-mysql

And there is config from appsettings.Production.json

  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://+:809"
      }
    }
  },

With compose-up, the asp.net core always listen under 809.

Is there any reason, the docker-compose file did not override the settings from appsettings.Production.json?

1 Answer 1

2

The configuration in appsettings.Production.json takes precedence over the ASPNETCORE_URLS environment variable. More specifically, configuration in a Kestrel section overrides the Urls configuration setting.

If you override the configuration key that represents the Kestrel endpoint you've configured in appsettings.Production.json, using the ASPNETCORE_KESTREL__ENDPOINTS__HTTP__URL environment variable, it works:

environment: 
    - ASPNETCORE_ENVIRONMENT=Production
    - ASPNETCORE_KESTREL__ENDPOINTS__HTTP__URL=http://+:80
Sign up to request clarification or add additional context in comments.

4 Comments

Normally environment variables take precedence over config file settings. Do you know why that isn't the case here?
@HansKilian It's less about configuration sources overriding others, and more about Kestrel preferring "endpoints" keys over the higher-level "urls" key. There's a test in the source that demonstrates this here. You can follow that through the AddressBinder.BindAsync method to see more about how it works.
@KirkLarkin I made a test with ASPNETCORE_KESTREL__ENDPOINTS__HTTP__URL under .net 5, it seems it does not work. I am afraid I need to modify the appsettings.Production.json
@Edward try Kestrel__EndPoints__Http__Url=http://+:80, works for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.