AspNet Core无法在docker上的Production中运行[“ ASPNETCORE_ENVIRONMENT = Production”]

时间:2018-10-26 12:52:52

标签: docker asp.net-core .net-core docker-compose dockerfile

我似乎无法使用ASPNETCORE_ENVIRONMENT = Production使我的aspnet核心应用程序在docker中运行,但是当我将环境改回Development时它可以工作。在生产环境中,我无法浏览到localhost:port,但是在dev中可以正常工作。我的撰写文件如下:

version: '3.4'
services:
  web:
    container_name: aspdemo
    image: user/aspdemo
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_URLS=http://+:22973;
      - 'Logging:LogLevel:Default=Debug'
      - 'Logging:LogLevel:System=Information'
      - 'Logging:LogLevel:Microsoft=Information'
      - 'ConnectionStrings:DefaultConnection=Server=dbserver;Database=demoDb;User=sa;Password=MyStrong!Pass;'
    ports:
      - "22973:22973"
    networks:
      default: {}
      be:
        aliases:
          - tokenserver

networks:
  be:
    external:
       name: backend

AppSettings.json

{
  "ConnectionStrings": {
    "DefaultConnection":     "Server=dbserver;Database=demoDb;User=sa;Password=MyStrong!Pass;"
  },
  "Portal_IP": "http://197.254.91.254",
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}

AppSettings.Development.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=dbserver;Database=demoDb;User=sa;Password=MyStrong!Pass;"
  },
  "Portal_IP": "http://localhost",
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

2 个答案:

答案 0 :(得分:1)

我看不到您的AppSettings.Production.json。如果要添加自定义配置,则可以添加不同的appSettings json。那就是您的配置文件名称应为 AppSettings.Production.json 。因为您已将环境更改为生产环境。

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=dbserver;Database=demoDb;User=sa;Password=MyStrong!Pass;"
  },
  "Portal_IP": "http://localhost",
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

答案 1 :(得分:0)

寻找docker-compose.override.yml并覆盖

环境:       -ASPNETCORE_ENVIRONMENT =生产

对我来说,这是我唯一可以控制要部署的环境的地方。 我试图删除docker-compose.override.yml,然后控制docker-compose.yml中的所有内容,但它不起作用。看来我们有一个错误?

奥斯丁