|
| 1 | +--- |
| 2 | +title: Deploy Azure Container Apps with the az containerapp up command |
| 3 | +description: How to deploy a container app with the az containerapp up command |
| 4 | +services: container-apps |
| 5 | +author: cebundy |
| 6 | +ms.service: container-apps |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 11/08/2022 |
| 9 | +ms.author: v-bcatherine |
| 10 | +--- |
| 11 | + |
| 12 | +# Deploy Azure Container Apps with the az containerapp up command |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +The `az containerapp up` command is a streamlined way to create and deploy container apps that primarily use default settings. However, you'll need to use the `az containerapp create` command for apps with customizations such as: |
| 17 | + |
| 18 | +- Dapr configuration |
| 19 | +- Secrets |
| 20 | +- Transport protocols |
| 21 | +- Custom domains |
| 22 | +- Storage mounts |
| 23 | + |
| 24 | +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. Note that the `az containerapp up` command isn't an abbreviation of the `az containerapp update` command. |
| 25 | + |
| 26 | +The `up` command can create or use existing resources including: |
| 27 | + |
| 28 | +- Resource group |
| 29 | +- Azure Container Registry |
| 30 | +- Container Apps environment and Log Analytics workspace |
| 31 | +- Your container app |
| 32 | + |
| 33 | +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. |
| 34 | + |
| 35 | + 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. |
| 36 | + |
| 37 | +To learn more about the `az containerapp up` command and its options, see [`az containerapp up`](/cli/azure/containerapp#az_containerapp_up). |
| 38 | + |
| 39 | +## Prerequisites |
| 40 | + |
| 41 | +| Requirement | Instructions | |
| 42 | +|--|--| |
| 43 | +| Azure account | If you don't have one, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). You need the *Contributor* or *Owner* permission on the Azure subscription to proceed. Refer to [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.md?tabs=current) for details. | |
| 44 | +| GitHub Account | If you use a GitHub repo, sign up for [free](https://github.com/join). | |
| 45 | +| Azure CLI | Install the [Azure CLI](/cli/azure/install-azure-cli).| |
| 46 | +|Local source code | You need to have a local source code directory if you use local source code. | |
| 47 | +| Existing Image | If you use an existing image, you'll need your registry server, image name, and tag. If you're using a private registry, you'll need your credentials. | |
| 48 | + |
| 49 | +## Set up |
| 50 | + |
| 51 | +1. Log in to Azure with the Azure CLI. |
| 52 | + |
| 53 | + ```azurecli |
| 54 | + az login |
| 55 | + ``` |
| 56 | +1. Next, install the Azure Container Apps extension for the CLI. |
| 57 | +
|
| 58 | + ```azurecli |
| 59 | + az extension add --name containerapp --upgrade |
| 60 | + ``` |
| 61 | +
|
| 62 | +1. Now that the current extension or module is installed, register the `Microsoft.App` namespace. |
| 63 | +
|
| 64 | + ```azurecli |
| 65 | + az provider register --namespace Microsoft.App |
| 66 | + ``` |
| 67 | +
|
| 68 | +1. Register the `Microsoft.OperationalInsights` provider for the Azure Monitor Log Analytics workspace. |
| 69 | +
|
| 70 | + ```azurecli |
| 71 | + az provider register --namespace Microsoft.OperationalInsights |
| 72 | + ``` |
| 73 | +
|
| 74 | +## Deploy from an existing image |
| 75 | +
|
| 76 | +You can deploy a container app that uses an existing image in a public or private container registry. If you are deploying from a private registry, you'll need to provide your credentials using the `--registry-server`, `--registry-username`, and `--registry-password` options. |
| 77 | +
|
| 78 | +In this example, the `az containerapp up` command performs the following actions: |
| 79 | +
|
| 80 | +1. Creates a resource group. |
| 81 | +1. Creates an environment and Log Analytics workspace. |
| 82 | +1. Creates and deploys a container app that pulls the image from a public registry. |
| 83 | +1. Sets the container app's ingress to external with a target port set to the specified value. |
| 84 | +
|
| 85 | +Run the following command to deploy a container app from an existing image. Replace the \<Placeholders\> with your values. |
| 86 | +
|
| 87 | +```azurecli |
| 88 | +az containerapp up \ |
| 89 | + --name <CONTAINER_APP_NAME> \ |
| 90 | + --image <REGISTRY_SERVER>/<IMAGE_NAME>:<TAG> \ |
| 91 | + --ingress external \ |
| 92 | + --target-port <PORT_NUMBER> |
| 93 | +``` |
| 94 | + |
| 95 | +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. |
| 96 | + |
| 97 | +```azurecli |
| 98 | +az containerapp up \ |
| 99 | + --name <CONTAINER_APP_NAME> \ |
| 100 | + --image <REGISTRY_SERVER>/<IMAGE_NAME>:<TAG> \ |
| 101 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 102 | + --environment <ENVIRONMENT_NAME> \ |
| 103 | + --ingress external \ |
| 104 | + --target-port <PORT_NUMBER> |
| 105 | +``` |
| 106 | + |
| 107 | +## Deploy from local source code |
| 108 | + |
| 109 | +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. |
| 110 | + |
| 111 | +The command can build the image with or without a Dockerfile. If building without a Dockerfile the following languages are supported: |
| 112 | + |
| 113 | +- .NET |
| 114 | +- Node.js |
| 115 | +- PHP |
| 116 | +- Python |
| 117 | +- Ruby |
| 118 | +- Go |
| 119 | + |
| 120 | +The following example shows how to deploy a container app from local source code. |
| 121 | + |
| 122 | +In the example, the `az containerapp up` command performs the following actions: |
| 123 | + |
| 124 | +1. Creates a resource group. |
| 125 | +1. Creates an environment and Log Analytics workspace. |
| 126 | +1. Creates a registry in Azure Container Registry. |
| 127 | +1. Builds the container image (using the Dockerfile if it exists). |
| 128 | +1. Pushes the image to the registry. |
| 129 | +1. Creates and deploys the container app. |
| 130 | + |
| 131 | +Run the following command to deploy a container app from local source code: |
| 132 | + |
| 133 | +```azurecli |
| 134 | + az containerapp up \ |
| 135 | + --name <CONTAINER_APP_NAME> \ |
| 136 | + --source <SOURCE_DIRECTORY>\ |
| 137 | + --ingress external |
| 138 | +``` |
| 139 | + |
| 140 | +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. |
| 141 | + |
| 142 | +If you've configured ingress through your Dockerfile or your app doesn't require ingress, you can omit the `ingress` option. |
| 143 | + |
| 144 | +The output of the command includes the URL for the container app. |
| 145 | + |
| 146 | +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. |
| 147 | + |
| 148 | +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. |
| 149 | + |
| 150 | +1. Make changes to the source code. |
| 151 | +1. Run the following command: |
| 152 | + |
| 153 | + ```azurecli |
| 154 | + az containerapp up \ |
| 155 | + --name <CONTAINER_APP_NAME> \ |
| 156 | + --source <SOURCE_DIRECTORY> \ |
| 157 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 158 | + --environment <ENVIRONMENT_NAME> |
| 159 | + ``` |
| 160 | +
|
| 161 | +## Deploy from a GitHub repository |
| 162 | +
|
| 163 | +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. |
| 164 | +
|
| 165 | +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. |
| 166 | +
|
| 167 | +The following example shows how to deploy a container app from a GitHub repository. |
| 168 | +
|
| 169 | +In the example, the `az containerapp up` command performs the following actions: |
| 170 | +
|
| 171 | +1. Creates a resource group. |
| 172 | +1. Creates an environment and Log Analytics workspace. |
| 173 | +1. Creates a registry in Azure Container Registry. |
| 174 | +1. Builds the container image using the Dockerfile. |
| 175 | +1. Pushes the image to the registry. |
| 176 | +1. Creates and deploys the container app. |
| 177 | +1. Creates a GitHub Actions workflow to build the container image and deploy the container app when future changes are pushed to the GitHub repository. |
| 178 | +
|
| 179 | +To deploy an app from a GitHub repository, run the following command: |
| 180 | +
|
| 181 | +```azurecli |
| 182 | +az containerapp up \ |
| 183 | + --name <CONTAINER_APP_NAME> \ |
| 184 | + --repo <GitHub repository URL> \ |
| 185 | + --ingress external |
| 186 | +``` |
| 187 | + |
| 188 | +If you've configured ingress through your Dockerfile or your app doesn't require ingress, you can omit the `ingress` option. |
| 189 | + |
| 190 | +Because the `up` command creates a GitHub Actions workflow, rerunning it to deploy changes to your app's image will have the unwanted effect of creating multiple workflows. Instead, push changes to your GitHub repository, and the GitHub workflow will automatically build and deploy your app. To change the workflow, edit the workflow file in GitHub. |
| 191 | + |
| 192 | +## Next steps |
| 193 | + |
| 194 | +> [!div class="nextstepaction"] |
| 195 | +> [Quickstart: Deploy your code to Azure Container Apps](quickstart-code-to-cloud.md) |
0 commit comments