I deployed an http trigger function using a code deployment to azure and it works functions are shown and respond with the appreciate data.
When I create a docker image, the image works locally but when I deploy to azure there is no functions. and trying to execute the function result in a 404 error.
I compared the environment variables and they are the same between the 2 function apps.
I spend the last 2 days reading blogs on this but have not found any real solution.
what am I missing?
Here is my Docker file:
# Base image with Python 3.9
FROM mcr.microsoft.com/azure-functions/python:4-python3.12
# Set environment variables to avoid writing .pyc files and buffering output
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
# Install git to clone the Bitbucket repository
RUN apt-get update && apt-get install -y git
ENV AZURE_FUNCTIONS_ENVIRONMENT=Development
#Copy secrets file
RUN mkdir /etc/secrets/
ENV FUNCTIONS_SECRETS_PATH=/etc/secrets
ENV AzureWebJobsSecretStorageType=Files
ADD host_secrets.json /etc/secrets/host.json
# Install dependencies from requirements.txt
COPY requirements.txt /
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code (optional, if you want to add any additional files or scripts)
COPY . /home/site/wwwroot
Here is my secrets file:
{
"masterKey": {
"name": "master",
"value": "p##########################################################",
"encrypted": false
},
"functionKeys": [{
"name": "default",
"value": "w##########################################################",
"encrypted": false
}]
}
Here is my environment variables:
[
{
"name": "APP_CONFIGURATION_LABEL",
"value": "production",
"slotSetting": false
},
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"value": "InstrumentationKey=a###################################;IngestionEndpoint=https://a###################.in.applicationinsights.azure.com/;LiveEndpoint=https://a################.livediagnostics.monitor.azure.com/;ApplicationId=d######################################",
"slotSetting": false
},
{
"name": "AzureFunctionsJobHost__Logging__Console__IsEnabled",
"value": "true",
"slotSetting": false
},
{
"name": "AzureWebJobsDashboard",
"value": "DefaultEndpointsProtocol=https;AccountName=a########################;AccountKey=q################################################################;EndpointSuffix=core.windows.net",
"slotSetting": false
},
{
"name": "AzureWebJobsScriptRoot",
"value": "/home/site/wwwroot",
"slotSetting": false
},
{
"name": "AzureWebJobsStorage",
"value": "DefaultEndpointsProtocol=https;AccountName=a#############################;AccountKey=q###############################################################################;EndpointSuffix=core.windows.net",
"slotSetting": false
},
{
"name": "DOCKER_ENABLE_CI",
"value": "true",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_PASSWORD",
"value": "G########################################################",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_URL",
"value": "https://#################.azurecr.io",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_USERNAME",
"value": "############",
"slotSetting": false
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~4",
"slotSetting": false
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "python",
"slotSetting": false
},
{
"name": "UseExpressBuild",
"value": "/tmp/.cache",
"slotSetting": false
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "#############################################################################",
"slotSetting": false
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "a#####################",
"slotSetting": false
},
{
"name": "WEBSITE_ENABLE_SYNC_UPDATE_SITE",
"value": "true",
"slotSetting": false
},
{
"name": "WEBSITE_HEALTHCHECK_MAXPINGFAILURES",
"value": "10",
"slotSetting": false
},
{
"name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS",
"value": "2",
"slotSetting": false
},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": "1",
"slotSetting": false
},
{
"name": "WEBSITE_TIME_ZONE",
"value": "Australia/Sydney",
"slotSetting": false
},
{
"name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
"value": "false",
"slotSetting": false
}
]
Looking at the log it show the docker image was successfully deployed. Here is the log:
025-01-17T04:51:32.535Z INFO - c861b3c01817 Extracting 33MB / 33MB
2025-01-17T04:51:32.643Z INFO - c861b3c01817 Pull complete
2025-01-17T04:51:32.678Z INFO - Digest: sha256:3#########################################################################
2025-01-17T04:51:32.683Z INFO - Status: Downloaded newer image for azuretestcreg.azurecr.io/azfunctiontest:latest
2025-01-17T04:51:32.699Z INFO - Pull Image successful, Time taken: 45 Seconds
2025-01-17T04:51:32.722Z INFO - Starting container for site
2025-01-17T04:51:32.727Z INFO - docker run -d -p 9131:80 --name austeamtest3_0_89c7e566 -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e WEBSITE_CORS_ALLOWED_ORIGINS=https://portal.azure.com -e WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=austeamTest3 -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=test6783.azurewebsites.net -e WEBSITE_INSTANCE_ID=5######################################################################### -e HTTP_LOGGING_ENABLED=1 testcreg.azurecr.io/azfunctiontest:latest
2025-01-17T04:51:35.762Z INFO - Initiating warmup request to container austeamtest3_0_89c7e566_msiProxy for site test6783
2025-01-17T04:51:35.825Z INFO - Container test6783_0_89c7e566_msiProxy for site austeamtest3 initialized successfully and is ready to serve requests.
2025-01-17T04:51:35.830Z INFO - Initiating warmup request to container austeamtest3_0_89c7e566 for site test6783
2025-01-17T04:51:40.439Z INFO - Container test6783_0_89c7e566 for site test6783 initialized successfully and is ready to serve requests.
2025-01-17T04:51:40.445Z INFO - Initiating warmup request to container austeamtest3_0_89c7e566_middleware for site test6783
2025-01-17T04:51:41.259Z INFO - Container test6783_0_89c7e566_middleware for site austeamtest3 initialized successfully and is ready to serve requests.
I have read blogs on this, tried add all the environment variables mentioned in the blogs.
I looked at the logs and tried to use the azure diagnostics, which does not give me anything.
Need the functions to be listed and be able to call the functions.
I have referred Create your first containerized Azure Functions to create a http trigger function locally in vs code and then deployed to Azure function app using Azure container registry.
While creating the function, it will create the docker file which will look like below.
FROM mcr.microsoft.com/azure-functions/python:4-python3.7
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY requirements.txt /
RUN pip install -r /requirements.txt
COPY . /home/site/wwwroot
Then, build and run the docker image by using below commands.
docker build --tag <DOCKER_ID>/azurefunctionsimage:v1.0.0 .
docker run -p 8080:80 -it <DOCKER_ID>/azurefunctionsimage:v1.0.0
Once, it is executed successfully locally, you can deploy your code to Azure container registry by using below commands.
az acr login --name <REGISTRY_NAME>
docker tag <DOCKER_ID>/azurefunctionsimage:v1.0.0 <LOGIN_SERVER>/azurefunctionsimage:v1.0.0
docker push <LOGIN_SERVER>/azurefunctionsimage:v1.0.0
Then, I created a function app with Premium plan and selected container image as shown below.
Add the registry details in Deployment Center.
After few minutes, you should be able to see the function endpoints.
I am able to execute the function in function app successfully.