函数主机不是 运行ning docker 运行 中的错误

Function host is not running error in docker run

我有一个函数应用程序,并计划使用 Azure KEDA 进行部署。将当前函数应用程序转换为 docker 并使用 docker run command 在本地测试相同内容时,出现以下错误。

Function host is not running.

它在 visual studio 中调试时有效,但在 Docker 中无效。其他 Whosebug 答案建议检查 host.json,我试过了,但没有修复它。

下面是我的host.json.

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Information",
      "Host": "Error",
      "Function": "Error",
      "Host.Aggregator": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 20
      }
    }
  }
}

Docker文件

FROM microsoft/dotnet:2.2-sdk AS installer-env

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish Projects/Projectxxx.csproj --output /home/site/wwwroot

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:2.0-appservice 
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

我做了两件事让它发挥作用。

  • <PackageReference Include="WindowsAzure.Storage" Version="9.3.2" /> 添加到 .csproj

  • 遗漏了一些环境变量。在 startup.cs
  • 中使用的 docker run -e 环境参数中缺少一些应用程序设置