This is a quickstart on how you start running Python function samples as a custom image (Container) with Docker.
- Quickstart Function Samples as a Custom image with Docker
git clone https://github.com/yokawasa/azure-functions-python-samples.git
This project include a set of multiple sample function and each function may have different required resources. Please check readme.md
included in each function sample (Check v2functions).
A minimum is an Azure Storage Account
which is necessary for all functions. Here is how you create:
RESOURCE_GROUP="<RESOURCE GROUPP MAME>"
REGION="<REGION NAME: eastus>"
az group create --name $RESOURCE_GROUP --location $REGION
RESOURCE_GROUP="<RESOURCE GROUPP MAME>"
REGION="<REGION NAME: eastus>"
STORAGE_ACCOUNT="<STORAGE ACCOUNT NAME>"
echo "Create an Azure Storage account: $STORAGE_ACCOUNT"
az storage account create --name $STORAGE_ACCOUNT \
--location $REGION \
--resource-group $RESOURCE_GROUP \
--sku Standard_LRS
The rest of resources such as Cosmos DB account and Computer Vision Subscription are optionals:
For CosmosDB Account and its database and collections, you can leverage the following helper script. Adding required params in the script and running will create a CosmosDB Account and database and collections.
For Computer Vision API subscription, you can leverage the following helper script. Likewise, add required params in the script and run it.
Let's build the image from the Docker file using docker build
command.
cd v2functions
# Build the image with `docker build` command
# docker build --tag <docker-id>/<imagename>:<tag> .
docker build --tag yoichikawasaki/azfuncpythonsamples:v0.0.1 .
You can also use a helper script - scripts/docker-build.sh
Now you're ready to run the app. You have 2 options
...
docker run -p 8080:80 -it \
-e AzureWebJobsStorage="$STORAGE_CONNECTION_STRING" \
$DOCKER_ID/$CONTAINER_IMAGE_NAME:$TAG
...
...
docker run -p 8080:80 -it \
-e AzureWebJobsStorage="$STORAGE_CONNECTION_STRING" \
-e MyStorageConnectionString="$STORAGE_CONNECTION_STRING" \
-e MyCosmosDBConnectionString="$COSMOSDB_CONNECTION_STRING" \
-e ComputerVisionSubscription="$COMPUTER_VSION_API_SUBSCRIPTION" \
-e ComputerVisionApiEndpoint="$COMPUTER_VSION_API_ENDPOINT" \
$DOCKER_ID/$CONTAINER_IMAGE_NAME:$TAG
...
Once you start the app with docker, let's send a test request to http-trigger-dump-request
function:
curl -s http://localhost:8080/api/http-trigger-dump-request |jq
{
"method": "GET",
"url": "http://localhost:8080/api/http-trigger-dump-request",
"headers": {
"accept": "*/*",
"host": "localhost:8080",
"user-agent": "curl/7.54.0"
},
"params": {},
"get_body": ""
}
By default, Console Logging is not enabled, and you can enable it by setting the following option as an ENV variable in Dockerfile or giving the option in running docker:
ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true