Azure Function Docker 不使用 http 触发器 [英] Azure Function Docker not working with http trigger

查看:16
本文介绍了Azure Function Docker 不使用 http 触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我创建了一个带有 HttpTrigger 的 Azure 函数(节点)的 docker 映像.这是默认生成的基本 HttpTrigger.我正在 Macbook Pro (MoJave) 上开发这个,我安装了以下工具.

Recently I have created a docker image with Azure Function (Node) having HttpTrigger. This is a basic HttpTrigger which generate by default. I'm developing this on Macbook Pro (MoJave) and I have following tools installed.

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

NodeJs - node/10.13.0 .NET Core 2.1 for macOS Azure Function core tools (via brew)

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

When I run the function locally with "func host start", it all works fine and I could see the function loading messages. Also I was able to execute the Azure function with trigger endpoint.However, when I try to build the Docker container and run the same, I can load the home page of the app but could not reach the function endpoint. In the log I could only see following;

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

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

My Docker file is as below (generated by Azure core tools);

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 触发器.

When I try to to use 'microsoft/azure-functions-runtime:v2.0.0-beta1' as base image, then I can see the function loading and could able to access the http trigger also.

有什么遗漏或者我需要使用不同的图片吗?

Is there anything missing or do I need to use a different image?

推荐答案

  1. 在 Dockerfile 中,添加 ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true 启用日志记录,设置为 基本图片中省略了所以我们现在必须手动完成.

  1. In Dockerfile, add ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true to enable logging, the setting is omitted in the basic image so we have to do it manually for now.

如果你得到 401 Unauthorized,找到文件 function.json,如果是 function(模板中的默认值),将 authLevel 更改为 anonymous.我们无法使用 anonymous 以外的身份验证级别访问本地容器中的 http 触发器.因为我们没有 函数键,在我们使用容器创建函数应用后可用.

If you got 401 Unauthorized, find the file function.json, change authLevel to anonymous if it was function(default value in template). We can't access http trigger in a local container with authlevel other than anonymous. Because we don't have function keys yet, which are available after we create a Function app using the container.

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

As for why we can access http trigger with function authlevel when we use func host start out of container, authorization is disabled regardless of the specified authentication level when running locally.

这篇关于Azure Function Docker 不使用 http 触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆