Create an Azure Container Apps environment
With your user information stored in environment variables, you’re ready to begin the first step in the deployment: creating an Azure Container Apps instance.
This involves three things:
- Creating a resource group.
- Creating the virtual network. In addition to the Container Apps environment, you’ll use this network in following labs to add more networking features.
- Deploying a new Azure Container Apps environment to the resource group and configuring it to use the virtual network that you created.
To learn more about deploying container apps, refer to Tutorial: Deploy your first container app.
Step-by-step guidance
-
Run the following commands to create a resource group, which you’ll use for all subsequent resources that you’ll create in this lab. Replace the <azure-region> placeholder with the name of the Azure region you want to use:
UNIQUEID=$(openssl rand -hex 3) APPNAME=petclinic RESOURCE_GROUP=rg-$APPNAME-$UNIQUEID LOCATION=<azure-region> az group create -g $RESOURCE_GROUP -l $LOCATION az configure --default group=$RESOURCE_GROUP
Not all regions support Azure Container Apps environments and Azure Database for MySQL - Flexible Server instances. For more info, please refer to Region availability.
This lab uses quite a few environment variables. If you’re using a codespace to run this lab and the codespace restarts, your environment variables will be lost. For methods to persist these environment variables across codespace sessions, go to the LabTips section.
-
Create a virtual network and subnet for your Container Apps environment to use:
VIRTUAL_NETWORK_NAME=vnet-$APPNAME-$UNIQUEID az network vnet create \ --resource-group $RESOURCE_GROUP \ --name $VIRTUAL_NETWORK_NAME \ --location $LOCATION \ --address-prefix 10.1.0.0/16 ACA_SUBNET_CIDR=10.1.0.0/27 az network vnet subnet create \ --resource-group $RESOURCE_GROUP \ --vnet-name $VIRTUAL_NETWORK_NAME \ --address-prefixes $ACA_SUBNET_CIDR \ --name aca-subnet \ --delegations Microsoft.App/environments
-
Store the subnet ID as an environment variable. You’ll need this ID when you create the Container Apps environment:
SUBNET_ID=$(az network vnet subnet show --resource-group $RESOURCE_GROUP --vnet-name $VIRTUAL_NETWORK_NAME --name aca-subnet --query id -o tsv)
-
Create a new Azure Container Apps environment in your resource group, and configure it to use the new subnet.
If you’ve already successfully run the
create-azure-resources.sh
script discussed in the installation instructions, you can skip this step.We’ll be creating the service on an Azure Container Apps Dedicated plan using the workload profiles option. This plan gives you more advanced features than the alternative Azure Container Apps Consumption plan type:
ACA_ENVIRONMENT=acalab-env-$APPNAME-$UNIQUEID az containerapp env create \ -n $ACA_ENVIRONMENT \ -g $RESOURCE_GROUP \ --location $LOCATION \ --enable-workload-profiles true \ --infrastructure-subnet-resource-id $SUBNET_ID \ --logs-destination none ACA_ENVIRONMENT_ID=$(az containerapp env show -n $ACA_ENVIRONMENT -g $RESOURCE_GROUP --query id -o tsv)
If you’re using Git Bash and get an error message related to the resource ID, run the command export MSYS_NO_PATHCONV=1. Then wait for the provisioning to complete, and try again. This might take about three minutes.
-
Confirm that the new resources have deployed correctly:
- In your browser, go to the Azure portal.
- Go to Resource groups, and select the new resource group you just created.
-
In the resource group overview, you should find your newly created Azure Container Apps environment and virtual network.
If you don’t immediately find the Container Apps environment in the resource group overview list, wait a moment and then select
Refresh
a few times until it appears.You may also notice an additional resource group (beginning with “ME_”) in your subscription. This resource group, which you created in this set of steps, will also contain any associated resources created to support the Container Apps environment and virtual network.