skip to Main Content

How do I get Azure Functions to correctly run my .NET function from a container?

Example repo that reproduces the concern: https://github.com/robrich/azure-functions

Public image built from the code above: robrich.azurecr.io/func1:0cc2c12e5da12319faf50750783063130c4daf35-main

I’ve run the tutorial from https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-custom-container using the Azure Functions section. This builds the C# function and the Dockerfile in Visual Studio 2022.

I provision the Azure Function in the portal using the Consumption plan and choose .NET Isolated 8.0 as my stack.

I’ve set WEBSITES_ENABLE_APP_SERVICE_STORAGE=false to ensure /home/site/wwwroot isn’t overwritten with blank content. See also:

Then I follow the instructions from https://github.com/Azure/functions-container-action to add the GitHub Actions build and deploy. See https://github.com/robrich/azure-functions/blob/main/.github/workflows/dotnet-build.yaml

When I build and deploy the container locally, the function runs just fine, and I get this console output:

info: Host.Startup[326]
      Reading functions metadata (Custom)
info: Host.Startup[327]
      0 functions found (Custom)
info: Host.Startup[315]
      1 functions loaded
info: Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcFunctionInvocationDispatcher[0]
      Worker process started and initialized.
info: Host.Startup[0]
      Generating 1 job function(s)
info: Host.Startup[0]
      Found the following functions:
      Host.Functions.Function1

When GitHub Actions deploys the container runs in Azure, the function is unavailable and I get this console output:

2024-12-07T02:29:47Z   [Information]   Loading functions metadata
2024-12-07T02:29:47Z   [Information]   Reading functions metadata (Custom)
2024-12-07T02:29:47Z   [Information]   0 functions found (Custom)
2024-12-07T02:29:47Z   [Information]   0 functions loaded

How do I get Azure Functions to correctly run my .NET function from a container?

2

Answers


  1. Chosen as BEST ANSWER

    It turns out that only the Premium or better Azure Function plan supports running in a container. If you use the Consumption plan, you don't get the option to "Deploy as Container Image". Without this option set (even if all the environment variables are set) it won't correctly start the container, and it'll error with 0 functions found. Flip over to a Premium or better plan, set the option "Deploy as Container Image" and everything works just fine.

    In the Azure Portal, when creating an Azure Function, this question is only present when creating a function on the Premium and better plans:

    Do you want to deploy code or container image?

    Without setting this question to "Container Image", the function deploys correctly via GitHub Actions, but does not start, noting 0 functions found.

    Switch to the Premium plan and everything starts up just fine.

    Azure Function premium plan


  2. I’ve faced the same problem. Locally, with Azure Functions Core Tools I could upload the functions without any problem. But deploying with Github Actions just won’t work. I didn’t solve it to that time. But here is a similar issue on Github, worth a look: https://github.com/Azure/functions-action/issues/192#issuecomment-1782920933

    Let me know if this works for you!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search