Azure Container Apps went General Available in May of 2022 and offers a great way to build cloud native apps with serverless containers.
Azure Container Apps behind the scenes is based on Kubernetes, it has been set up and is maintained by Microsoft. The service is setup in a serverless
way where you only have to worry about deploying your apps and not have to worry about maintanance.
A couple of features that can be used are:
For a complete list of features you can visit the docs.
In the getting started example the following features are used:
Steps to perform:
sign in to Azure from the CLI, and set your default subscription if you have access to multiple subscriptions.
az login
az account set --subscription <<subscriptionid>>
Install the Azure Container Apps extension for the CLI.
az extension add --name containerapp --upgrade
Register the Microsoft.App
namespace, and the Microsoft.OperationalInsights
provider for the Azure Monitor Log Analytics Workspace if you have not used it before.
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
az provider register --namespace Microsoft.ContainerRegistry
Set a couple of variables
$RESOURCE_GROUP="rg-mycontainer-apps"
$LOCATION="westeurope"
$CONTAINERAPPS_ENVIRONMENT="my-environment"
$ACR_NAME="acrmycontainerapps01"
Create the resource group
az group create `
--name $RESOURCE_GROUP `
--location $LOCATION
Store custom containers in ACR to use with Azure Container Apps.
az acr create `
--resource-group $RESOURCE_GROUP `
--name $ACR_NAME `
--sku Basic `
--query loginServer `
--output tsv
Build the images and upload to ACR
$ACR_SERVER=$(az acr show -n $ACR_NAME --query loginServer -o tsv)
az acr build -r $ACR_NAME -t $ACR_SERVER/app:v1 ./azure-container-apps-demo -f ./azure-container-apps-demo/app/Dockerfile
az acr build -r $ACR_NAME -t $ACR_SERVER/api:v1 ./azure-container-apps-demo -f ./azure-container-apps-demo/api/Dockerfile
az containerapp env create `
--name $CONTAINERAPPS_ENVIRONMENT `
--resource-group $RESOURCE_GROUP `
--location $LOCATION
Create the containers in Azure Container Apps and configure with the settings:
az acr update --name $ACR_NAME --admin-enabled
$password=$(az acr credential show --name $ACR_NAME --query 'passwords[0].value' -o tsv)
az containerapp create `
--name api1 `
--resource-group $RESOURCE_GROUP `
--environment $CONTAINERAPPS_ENVIRONMENT `
--image $ACR_SERVER/api:v1 `
--ingress 'internal' `
--target-port 80 `
--registry-server $ACR_SERVER `
--registry-username $ACR_NAME `
--registry-password $password `
--query properties.configuration.ingress.fqdn
$api_base_url = $(az containerapp show --name api --resource-group $RESOURCE_GROUP --query 'properties.configuration.ingress.fqdn' -o tsv)
az containerapp create `
--name app1 `
--resource-group $RESOURCE_GROUP `
--environment $CONTAINERAPPS_ENVIRONMENT `
--image $ACR_SERVER/app:v1 `
--target-port 80 `
--ingress 'external' `
--registry-server $ACR_SERVER `
--registry-username $ACR_NAME `
--registry-password $password `
--env-vars API_BASE_URL=$api_base_url `
--query properties.configuration.ingress.fqdn
After creating all resources you should have the following resources in azure:
You can test if the app is working by openening the app, the url of the app can be found in the settings of the container app:
The first request to the site could be slow as the default settings of this app running on 0 instances.