6
votes

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?

1
Does my solution work for you? If so could you accept it for others to refer? Otherwise feel free to ask any further question.Jerry Liu
Hi Jerry, Sorry could not reply you before. Yes it worked as a charm :) Thanks for pointing out to the function security configuration & logging console setting. Logging console setting is really useful. Cheers.Melanga

1 Answers

9
votes
  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.

  2. 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.