Azure Function Docker 无法使用 http 触发器

标签 azure docker azure-functions

最近,我使用具有 HttpTrigger 的 Azure Function(节点)创建了一个 docker 镜像。这是默认生成的基本 HttpTrigger。我正在 Macbook Pro (MoJave) 上开发此程序,并且安装了以下工具。

NodeJs - 节点/10.13.0 适用于 macOS 的 .NET Core 2.1 Azure Function 核心工具(通过brew)

当我使用“func host start”在本地运行该函数时,一切正常,我可以看到函数加载消息。我还能够使用触发端点执行 Azure 函数。但是,当我尝试构建 Docker 容器并运行相同的容器时,我可以加载应用程序的主页,但无法到达函数端点。在日志中我只能看到以下内容;

Hosting environment: Production
Content root path: /
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

我的 Docker 文件如下(由 Azure 核心工具生成);

FROM mcr.microsoft.com/azure-functions/node:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
COPY . /home/site/wwwroot

当我尝试使用“microsoft/azure-functions-runtime:v2.0.0-beta1”作为基础镜像时,我可以看到函数加载并且也可以访问http触发器。

是否缺少任何内容或者我需要使用不同的图像?

最佳答案

  1. 在 Dockerfile 中,添加 ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true 以启用日志记录,设置为 omitted in the basic image所以我们现在必须手动完成。

  2. 如果出现 401 Unauthorized,请找到文件 function.json,如果是 function(模板中的默认值),请将 authLevel 更改为 anonymous。我们无法在具有除 anonymous 之外的 authlevel 的本地容器中访问 http 触发器。因为我们没有function keys然而,在我们使用容器创建 Function 应用程序后,它们就可用了。

    至于为什么我们在容器外使用func host start时可以通过function authlevel访问http触发器,本地运行时无论指定的认证级别如何,授权都会被禁用.

关于Azure Function Docker 无法使用 http 触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53412259/

相关文章:

通过 Docker 和 Visual Studio 发布到 Azure 时,Azure 函数 HTTP 请求 404

typescript - Azure Function 写入 CosmosDB 和错误处理

asp.net - Azure 中的 Windows AD 用户模拟

azure - Windows Azure - 在网站和虚拟机之间进行通信,无需启用外部/远程访问

Azure 数据工厂查询

docker - 我可以从 docker 容器内部连接到远程数据库服务器吗?

Azure 函数 - “在主机运行时遇到错误 (InternalServerError)

c# - 从应用程序设置中定义的 KeyVault 检索 secret

docker - 如何在创建(声明)持久卷时创建文件?

docker - logstash-5.x gelf输入多行编解码器不起作用