Share via

Containerized Python Azure Function cannot start locally

Maria Dąbrowiecka 105 Reputation points
2025-04-02T12:50:35.6066667+00:00

Hi all,

I followed https://learn.microsoft.com/en-us/azure/azure-functions/functions-deploy-container?tabs=acr%2Cbash%2Cazure-cli&pivots=programming-language-python
and I can build docker image on my local machine but starting the container results in failure:

fail: Host.Startup[402]
      The 'function' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.function'. Microsoft.Azure.WebJobs.Extensions.Storage.Blobs: Storage account connection string 'AzureWebJobsStorage' does not exist. Make sure that it is a defined App Setting.
Hosting environment: Production

This is my Dockerfile:

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/python:4-python3.12-appservice
FROM mcr.microsoft.com/azure-functions/python:4-python3.12

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
    PYTHON_ISOLATE_WORKER_DEPENDENCIES=1

COPY requirements.txt /
RUN pip install requirements.txt

COPY . /home/site/wwwroot

I put the value of AzureWebJobsStorage to local.settings.json and removed this file from .dockerignore

Is there anything I'm missing? Btw it only doesn't when I run locally

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


Answer accepted by question author
  1. Alex Burlachenko 20,505 Reputation points MVP Volunteer Moderator
    2025-04-02T14:59:39.0533333+00:00

    Hi Maria,

    Thx for posting your question here at Q&A portal. The problem you're experiencing is that while you've added AzureWebJobsStorage to local.settings.json and removed it from .dockerignore, the Azure Functions runtime in the container isn't picking up these settings. Some issues in your current setup:

    local.settings.json isn't automatically loaded in containers, this file is only used by the Functions Core Tools (func host start), not by the container runtime. Missing WORKER_RUNTIME setting - Python functions require this environment variable. Potential pip install issue - your run pip install requirements.txt should be RUN pip install -r requirements.txt ....

    FROM mcr.microsoft.com/azure-functions/python:4-python3.12
    
    ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
        AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
        PYTHON_ISOLATE_WORKER_DEPENDENCIES=1 \
        FUNCTIONS_WORKER_RUNTIME=python \
        AzureWebJobsStorage="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;QueueEndpoint=http://azurite:10001/devstoreaccount1;TableEndpoint=http://azurite:10002/devstoreaccount1;"
    
    COPY requirements.txt /
    RUN pip install -r requirements.txt
    
    COPY . /home/site/wwwroot
    

    I would like to post some recommendations for local development if you like.

    Use Azurite for local storage

    docker run -d -p 10000:10000 -p 10001:10001 -p 10002:10002 --name azurite mcr.microsoft.com/azure-storage/azurite
    

    Build and run your function with networking

    docker build -t mypythonfunction .
    docker run -p 8080:80 --link azurite -e AzureWebJobsStorage="UseDevelopmentStorage=true" mypythonfunction
    

    The UseDevelopmentStorage=true setting only works when your function can connect to Azurite on the default ports. For production deployments, you'll need to provide a real storage account connection string. Make sure your requirements.txt file includes azure-functions package. Hope that would help.

    rgds, Alex

    P.s. If my answer help to you, please Accept my answer

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.