Home > database >  ASPNETCORE_URLS from docker-compose did not override appsetting.production.json
ASPNETCORE_URLS from docker-compose did not override appsetting.production.json

Time:12-15

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?

CodePudding user response:

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
  • Related