【问题标题】:AspNet Core doesn't run in Production on docker ["ASPNETCORE_ENVIRONMENT=Production"]AspNet Core 不在 docker ["ASPNETCORE_ENVIRONMENT=Production"] 上的生产环境中运行
【发布时间】:2019-03-31 05:49:29
【问题描述】:

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

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"
    }
  }
}

【问题讨论】:

  • 你能添加你的 appSettings.Production.json 和 appSettings.Development.json 吗?
  • @CelalYildirim 检查以上更新
  • 您好,您找到解决问题的方法了吗?

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


【解决方案1】:

我看不到您的 AppSettings.Production.json。如果要添加自定义配置,可以添加不同的 appSettings jsons。那就是你的配置文件名应该是 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"
    }
  }
}

【讨论】:

    【解决方案2】:

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

    环境: - ASPNETCORE_ENVIRONMENT=生产

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

    奥斯汀

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2020-10-06
      • 2017-08-13
      • 2012-12-26
      相关资源
      最近更新 更多