Docker 未能在heroku上部署ASP.netcore 3.1停靠应用程序,但容器可在本地服务器上运行

Docker 未能在heroku上部署ASP.netcore 3.1停靠应用程序,但容器可在本地服务器上运行,docker,asp.net-core,heroku,asp.net-core-webapi,Docker,Asp.net Core,Heroku,Asp.net Core Webapi,几天来,我一直在寻找很多教程,试图找到我的解决方案,但我就是找不到 概述: 我正在构建一个Asp.net核心(3.1)应用程序,我已经设置好在docker上运行。我的目标是将其部署到heroku 问题: 我可以在本地使用docker容器运行,但当我将其部署到heroku(创建映像时没有任何问题)时,我会收到错误屏幕消息: “应用程序错误 应用程序中出现错误,无法为您的页面提供服务。如果您是应用程序所有者,请检查日志以了解详细信息。您可以通过Heroku CLI使用命令“ 设置 希罗库: dyn

几天来,我一直在寻找很多教程,试图找到我的解决方案,但我就是找不到

概述: 我正在构建一个Asp.net核心(3.1)应用程序,我已经设置好在docker上运行。我的目标是将其部署到heroku

问题: 我可以在本地使用docker容器运行,但当我将其部署到heroku(创建映像时没有任何问题)时,我会收到错误屏幕消息:

“应用程序错误 应用程序中出现错误,无法为您的页面提供服务。如果您是应用程序所有者,请检查日志以了解详细信息。您可以通过Heroku CLI使用命令“

设置

希罗库:

  • dyno正在使用:api/bin/sh-c ASPNETCORE\u url\=:\$PORT\dotnet\
  • 构建包:
代码

Dockerfile


WORKDIR /src
COPY *.sln .
COPY Ecomm.UnitTests/*.csproj Ecomm.UnitTests/
COPY Ecomm.Api/*.csproj Ecomm.Api/
RUN dotnet restore
COPY . .

# testing
FROM build AS testing
WORKDIR /src/Ecomm.Api
RUN dotnet build
WORKDIR /src/Ecomm.UnitTests
RUN dotnet test

# publish
FROM build AS publish
WORKDIR /src/Ecomm.Api
RUN dotnet publish -c Release -o /src/publish



FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /src
COPY --from=publish /src/publish .
# heroku uses the following
CMD ASPNETCORE_URLS=http://*:$PORT dotnet Ecomm.Api.dll
Program.cs(默认脚本)

Launchsettings.json

    "Ecomm.Api": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "/weatherforecast",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    }
本地运行容器与部署到heroku之间的比较

用于推送Heroku容器寄存器的方法:

  docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
  heroku container:push api -a $HEROKU_APP_NAME --recursive 
  heroku container:release api -a $HEROKU_APP_NAME
heroku中的错误日志:

2020-01-18T14:53:32.255720+00:00 heroku[api.1]: State changed from crashed to starting

2020-01-18T14:53:35.853732+00:00 heroku[api.1]: Starting process with command `/bin/sh -c ASPNETCORE_URLS\=http://\*:\59573\ dotnet\ Ecomm.Api.dll`

2020-01-18T14:53:36.494742+00:00 heroku[api.1]: State changed from starting to up

2020-01-18T14:53:37.754733+00:00 app[api.1]: Hosting environment: Production

2020-01-18T14:53:37.754802+00:00 app[api.1]: Content root path: /src

2020-01-18T14:53:37.754925+00:00 app[api.1]: Now listening on: http://[::]:59573

2020-01-18T14:53:37.754946+00:00 app[api.1]: Application started. Press Ctrl+C to shut down.

2020-01-18T14:53:39.762409+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=dariorega-ecomm-api.herokuapp.com request_id=7538ce41-5d5e-4081-b214-eb1e50fdcc6c fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https

2020-01-18T14:53:40.075446+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=dariorega-ecomm-api.herokuapp.com request_id=4f1ff94a-eb45-4301-9c3a-74ece82abe84 fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https

2020-01-18T14:53:51.155230+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/api" host=dariorega-ecomm-api.herokuapp.com request_id=1cc3eeac-1ce5-4a67-82e0-ee680beecc90 fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https

2020-01-18T14:53:51.440188+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=dariorega-ecomm-api.herokuapp.com request_id=caa51bcd-a153-444b-88b5-c024d1b2ae84 fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https

2020-01-18T14:53:56.045125+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/weatherforecast" host=dariorega-ecomm-api.herokuapp.com request_id=bcdc8195-9da6-4258-a48b-4614d885302a fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https

2020-01-18T14:53:56.292724+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=dariorega-ecomm-api.herokuapp.com request_id=2329aa44-bdb0-43e3-bbbf-58bd87a09f8c fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
我在本地容器中获得的日志: 运行docker容器后,使用同一dockerfile运行:

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:5000

info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.

info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production

info: Microsoft.Hosting.Lifetime[0]
      Content root path: /src

warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect
但它是有效的

结论

    "Ecomm.Api": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "/weatherforecast",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    }
我已经在docker文件中尝试了很多方法,或者编辑了定义useUrl方法的program.cs,但是我仍然无法让它工作。我不知道是否与http/https过程有关,因为https没有设置/工作。heroku使用https。 或者我应该在某处定义一个url?欢迎任何帮助! 提前感谢您花时间阅读此

尝试设置HttpsRedirection和ForwardedHeaders选项

注意:您使用不带dotnetcore构建包的容器部署:)

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:5000

info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.

info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production

info: Microsoft.Hosting.Lifetime[0]
      Content root path: /src

warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect