In this lab you will containerize an existing Python application using the Azure CLI, a private Azure Container Registry, and Azure Container Registry Tasks. You will then deploy it to Azure Container Apps.
Azure Container Apps enables you to run microservices and containerized applications on a serverless platform. With Container Apps, you enjoy the benefits of running containers while leaving behind the concerns of manually configuring cloud infrastructure and complex container orchestrators.
- An Azure Subscription (e.g. Free or Student account)
- The Azure CLI
- Bash shell (e.g. macOS, Linux, Windows Subsystem for Linux (WSL), Multipass, Azure Cloud Shell, GitHub Codespaces, etc)
git clone https://github.com/asw101/python-fastapi-pypy.git
cd python-fastapi-pypy/
If this is the first time you have used Azure Container Apps from the Azure CLI, or with your Azure Account, you will need to install the containerapp
extension, and register the resource providers for Microsoft.App
and Microsoft.OperationalInsights
using the following commands.
az extension add --name containerapp
az provider register --namespace Microsoft.App --wait
az provider register --namespace Microsoft.OperationalInsights --wait
RESOURCE_GROUP="my-container-apps"
LOCATION="canadacentral"
CONTAINERAPPS_ENVIRONMENT="my-environment"
SUBSCRIPTION_ID=$(az account show --query id --out tsv)
SCOPE="/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}"
[[ -z "${RANDOM_STR:-}" ]] && RANDOM_STR=$(echo -n "$SCOPE" | shasum | head -c 6)
ACR_NAME="acr${RANDOM_STR}"
ACR_IMAGE_NAME="pypy-fastapi:latest"
az group create \
--name $RESOURCE_GROUP \
--location $LOCATION
Quickstart (docs.microsoft.com)
az acr create --resource-group $RESOURCE_GROUP \
--name $ACR_NAME \
--sku Basic \
--admin-enabled true
az acr build -t $ACR_IMAGE_NAME -r $ACR_NAME .
CONTAINER_IMAGE="${ACR_NAME}.azurecr.io/${ACR_IMAGE_NAME}"
REGISTRY_SERVER="${ACR_NAME}.azurecr.io"
REGISTRY_USERNAME="${ACR_NAME}"
REGISTRY_PASSWORD=$(az acr credential show -n $ACR_NAME --query 'passwords[0].value' --out tsv)
echo "$CONTAINER_IMAGE"
Quickstart (docs.microsoft.com)
az containerapp env create \
--name $CONTAINERAPPS_ENVIRONMENT \
--resource-group $RESOURCE_GROUP \
--location $LOCATION
az containerapp create \
--name my-container-app \
--resource-group $RESOURCE_GROUP \
--environment $CONTAINERAPPS_ENVIRONMENT \
--image "$CONTAINER_IMAGE" \
--registry-server "$REGISTRY_SERVER" \
--registry-username "$REGISTRY_USERNAME" \
--registry-password "$REGISTRY_PASSWORD" \
--target-port 80 \
--ingress 'external'
CONTAINERAPP_FQDN=$(az containerapp show --resource-group $RESOURCE_GROUP \
--name my-container-app \
--query properties.configuration.ingress.fqdn \
--out tsv)
echo "https://${CONTAINERAPP_FQDN}"
curl "https://${CONTAINERAPP_FQDN}/"
az group delete \
--name $RESOURCE_GROUP
- The sample in section 1 is originally from https://github.com/tonybaloney/ants-azure-demos, which is also referenced in step 1 of the video walkthrough. The updated sample is at: https://github.com/asw101/python-fastapi-pypy.