Deploy Azure Container Apps with the az containerapp up command
The az containerapp up
(or up
) command is the fastest way to deploy an app in Azure Container Apps from an existing image, local source code, or a GitHub repo. With this single command, you can have your container app up and running in minutes.
The az containerapp up
command is a streamlined way to create and deploy container apps that primarily use default settings. However, you need to run other CLI commands to configure more advanced settings:
- Dapr:
az containerapp dapr enable
- Secrets:
az containerapp secret set
- Transport protocols:
az containerapp ingress update
To customize your container app's resource or scaling settings, you can use the up
command and then the az containerapp update
command to change these settings. The az containerapp up
command isn't an abbreviation of the az containerapp update
command.
The up
command can create or use existing resources including:
- Resource group
- Azure Container Registry
- Container Apps environment and Log Analytics workspace
- Your container app
The command can build and push a container image to an Azure Container Registry (ACR) when you provide local source code or a GitHub repo. When you're working from a GitHub repo, it creates a GitHub Actions workflow that automatically builds and pushes a new container image when you commit changes to your GitHub repo.
If you need to customize the Container Apps environment, first create the environment using the az containerapp env create
command. If you don't provide an existing environment, the up
command looks for one in your resource group and, if found, uses that environment. If not found, it creates an environment with a Log Analytics workspace.
To learn more about the az containerapp up
command and its options, see az containerapp up
.
Prerequisites
Requirement | Instructions |
---|---|
Azure account | If you don't have one, create a trial subscription. You need the Contributor or Owner permission on the Azure subscription to proceed. Refer to Assign Azure roles using the Azure portal for details. |
GitHub Account | If you use a GitHub repo, sign up for free. |
Azure CLI | Install the Azure CLI. |
Local source code | You need to have a local source code directory if you use local source code. |
Existing Image | If you use an existing image, you need your registry server, image name, and tag. If you're using a private registry, you need your credentials. |
Set up
Sign in to Azure with the Azure CLI.
az cloud set -n AzureChinaCloud az login # az cloud set -n AzureCloud //means return to Public Azure.
Next, install the Azure Container Apps extension for the CLI.
az extension add --name containerapp --upgrade
Now that the current extension or module is installed, register the
Microsoft.App
namespace.az provider register --namespace Microsoft.App
Register the
Microsoft.OperationalInsights
provider for the Azure Monitor Log Analytics workspace.az provider register --namespace Microsoft.OperationalInsights
Deploy from an existing image
You can deploy a container app that uses an existing image in a public or private container registry. If you're deploying from a private registry, you need to provide your credentials using the --registry-server
, --registry-username
, and --registry-password
options.
In this example, the az containerapp up
command performs the following actions:
- Creates a resource group.
- Creates an environment and Log Analytics workspace.
- Creates and deploys a container app that pulls the image from a public registry.
- Sets the container app's ingress to external with a target port set to the specified value.
Run the following command to deploy a container app from an existing image. Replace the <PLACEHOLDERS> with your values.
az containerapp up \
--name <CONTAINER_APP_NAME> \
--image <REGISTRY_SERVER>/<IMAGE_NAME>:<TAG> \
--ingress external \
--target-port <PORT_NUMBER>
You can use the up
command to redeploy a container app. If you want to redeploy with a new image, use the --image
option to specify a new image. Ensure that the --resource-group
and environment
options are set to the same values as the original deployment.
az containerapp up \
--name <CONTAINER_APP_NAME> \
--image <REGISTRY_SERVER>/<IMAGE_NAME>:<TAG> \
--resource-group <RESOURCE_GROUP_NAME> \
--environment <ENVIRONMENT_NAME> \
--ingress external \
--target-port <PORT_NUMBER>
Deploy from local source code
When you use the up
command to deploy from a local source, it builds the container image, pushes it to a registry, and deploys the container app. It creates the registry in Azure Container Registry if you don't provide one.
The command can build the image with or without a Dockerfile. If building without a Dockerfile the following languages are supported:
- .NET
- Node.js
- PHP
- Python
The following example shows how to deploy a container app from local source code.
In the example, the az containerapp up
command performs the following actions:
- Creates a resource group.
- Creates an environment and Log Analytics workspace.
- Creates a registry in Azure Container Registry.
- Builds the container image (using the Dockerfile if it exists).
- Pushes the image to the registry.
- Creates and deploys the container app.
Run the following command to deploy a container app from local source code:
az containerapp up \
--name <CONTAINER_APP_NAME> \
--source <SOURCE_DIRECTORY>\
--ingress external
When the Dockerfile includes the EXPOSE instruction, the up
command configures the container app's ingress and target port using the information in the Dockerfile.
If you configure ingress through your Dockerfile or your app doesn't require ingress, you can omit the ingress
option.
The output of the command includes the URL for the container app.
If there's a failure, you can run the command again with the --debug
option to get more information about the failure. If the build fails without a Dockerfile, you can try adding a Dockerfile and running the command again.
To use the az containerapp up
command to redeploy your container app with an updated image, include the --resource-group
and --environment
arguments. The following example shows how to redeploy a container app from local source code.
Make changes to the source code.
Run the following command:
az containerapp up \ --name <CONTAINER_APP_NAME> \ --source <SOURCE_DIRECTORY> \ --resource-group <RESOURCE_GROUP_NAME> \ --environment <ENVIRONMENT_NAME>
Deploy from a GitHub repository
When you use the az containerapp up
command to deploy from a GitHub repository, it generates a GitHub Actions workflow that builds the container image, pushes it to a registry, and deploys the container app. The command creates the registry in Azure Container Registry if you don't provide one.
A Dockerfile is required to build the image. When the Dockerfile includes the EXPOSE instruction, the command configures the container app's ingress and target port using the information in the Dockerfile.
The following example shows how to deploy a container app from a GitHub repository.
In the example, the az containerapp up
command performs the following actions:
- Creates a resource group.
- Creates an environment and Log Analytics workspace.
- Creates a registry in Azure Container Registry.
- Builds the container image using the Dockerfile.
- Pushes the image to the registry.
- Creates and deploys the container app.
- Creates a GitHub Actions workflow to build the container image and deploy the container app when future changes are pushed to the GitHub repository.
To deploy an app from a GitHub repository, run the following command:
az containerapp up \
--name <CONTAINER_APP_NAME> \
--repo <GitHub repository URL> \
--ingress external
If you configure ingress through your Dockerfile or your app doesn't require ingress, you can omit the ingress
option.
Because the up
command creates a GitHub Actions workflow, rerunning it to deploy changes to your app's image has the unwanted effect of creating multiple workflows. Instead, push changes to your GitHub repository, and the GitHub workflow automatically builds and deploys your app. To change the workflow, edit the workflow file in GitHub.