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 - node/10.13.0 .NET Core 2.1 for macOS Azure Function core tools (via brew)
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.
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
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?
Azure Functions may be invoked via HTTP requests to build serverless APIs and respond to webhooks.
The most common cause for Azure Functions not getting triggered is that triggers are not synced properly. You can sync triggers in one of three ways: Restart your function app in the Azure portal.
To start your function in Visual Studio in debug mode: Press F5. If prompted, accept the request from Visual Studio to download and install Azure Functions Core (CLI) tools. You might also need to enable a firewall exception so that the tools can handle HTTP requests.
Navigate to your function app in the Azure portal, select App Keys, and then the _master key. In the Edit key section, copy the key value to your clipboard, and then select OK. After copying the _master key, select Code + Test, and then select Logs.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With