This project demonstrates how to create an Azure Function App using Python and Docker.
First, create a new Azure Function App project:
func init az_func_app_with_docker --python
cd az_func_app_with_docker
Create a new HTTP-triggered function:
func new --name HelloWorld --template "HTTP trigger" --authlevel "anonymous"
Update the function code in function_app.py
as needed.
Ensure you have a Dockerfile
in the root of your project with the necessary content.
Build the Docker image:
docker build -t az-func-app .
Run the Docker container:
docker run -p 8080:80 az-func-app
You can test the function by navigating to http://localhost:8080/api/HelloWorld
in your web browser or using a tool like curl
:
curl http://localhost:8080/api/HelloWorld?name=Azure
You should see the response:
Hello, Azure. This HTTP triggered function executed successfully.
Login to Azure:
az login
Create a resource group:
az group create --name myResourceGroup --location eastus
Create a storage account:
az storage account create --name mystorageaccount --location eastus --resource-group myResourceGroup --sku Standard_LRS
Create a function app:
az functionapp create --resource-group myResourceGroup --consumption-plan-location eastus --runtime python --functions-version 3 --name myfuncapp --storage-account mystorageaccount
Deploy the function app:
func azure functionapp publish myfuncapp
You have successfully created and deployed an Azure Function App using Python and Docker.