Azure Function Docker无法与http触发器一起使用 [英] Azure Function Docker not working with http trigger

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

问题描述

最近,我使用具有HttpTrigger的Azure Function(节点)创建了一个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.

NodeJ-节点/10.13.0 适用于macOS的.NET Core 2.1 Azure 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以外的authlevel的本地容器中访问http触发器.因为我们没有功能键,但是在我们使用容器创建Function应用之后,这些键才可用.

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触发器的原因,在本地运行时,无论指定的身份验证级别如何,都将禁用授权.

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天全站免登陆