|
| 1 | +--- |
| 2 | +title: "Quickstart: Use Azure App Configuration in Azure Container Apps" |
| 3 | +description: Learn how to connect a containerized application to Azure App Configuration, using Service Connector. |
| 4 | +services: azure-app-configuration |
| 5 | +author: maud-lv |
| 6 | +ms.service: azure-app-configuration |
| 7 | +ms.custom: service-connector |
| 8 | +ms.topic: quickstart |
| 9 | +ms.date: 03/02/2023 |
| 10 | +ms.author: malev |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +# Quickstart: Use Azure App Configuration in Azure Container Apps |
| 15 | + |
| 16 | +In this quickstart, you will use Azure App Configuration in an app running in Azure Container Apps. This way, you can centralize the storage and management of the configuration of your apps in Container Apps. This quickstart leverages the ASP.NET Core app created in [Quickstart: Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md). You will containerize the app and deploy it to Azure Container Apps. Complete the quickstart before you continue. |
| 17 | + |
| 18 | +> [!TIP] |
| 19 | +> While following this quickstart, preferably register all new resources within a single resource group, so that you can regroup them all in a single place and delete them faster later on if you don't need them anymore. |
| 20 | +
|
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +- An application using an App Configuration store. If you don't have one, create an instance using the [Quickstart: Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md). |
| 24 | +- An Azure Container Apps instance. If you don't have one, create an instance using the [Azure portal](/azure/container-apps/quickstart-portal) or [the CLI](/azure/container-apps/get-started). |
| 25 | +- [Docker Desktop](https://www.docker.com/products/docker-desktop) |
| 26 | +- The [Azure CLI](/cli/azure/install-azure-cli) |
| 27 | +--- |
| 28 | + |
| 29 | +## Connect Azure App Configuration to the container app |
| 30 | + |
| 31 | +In the Azure portal, navigate to your Container App instance. Follow the [Service Connector quickstart for Azure Container Apps](../service-connector/quickstart-portal-container-apps.md) to create a service connection with your App Configuration store using the settings below. |
| 32 | + |
| 33 | +- In the **Basics** tab: |
| 34 | + - select **App Configuration** for **Service type** |
| 35 | + - pick your App Configuration store for "**App Configuration**" |
| 36 | + |
| 37 | + :::image type="content" border="true" source="media\connect-container-app\use-service-connector.png" alt-text="Screenshot the Azure platform showing a form in the Service Connector menu in a Container App." lightbox="media\connect-container-app\use-service-connector.png"::: |
| 38 | + |
| 39 | +- In the **Authentication** tab: |
| 40 | + - pick **Connection string** authentication type and **Read-Only** for "**Permissions for the connection string** |
| 41 | + - expand the **Advanced** menu. In the Configuration information, there should be an environment variable already created called "AZURE_APPCONFIGURATION_CONNECTIONSTRING". Edit the environment variable by selecting the icon on the right and change the name to *ConnectionStrings__AppConfig*. We need to make this change as *ConnectionStrings__AppConfig* is the name of the environment variable the application built in the [ASP.NET Core quickstart](./quickstart-aspnet-core-app.md) will look for. This is the environment variable which contains the connection string for App Configuration. If you have used another application to follow this quickstart, please use the corresponding environment variable name. Then select **Done**. |
| 42 | +- Use default values for everything else. |
| 43 | + |
| 44 | +Once done, an environment variable named **ConnectionStrings__AppConfig** will be added to the container of your Container App. Its value is a reference of the Container App secret, the connection string of your App Configuration store. |
| 45 | + |
| 46 | +## Build a container |
| 47 | + |
| 48 | +1. Run the [dotnet publish](/dotnet/core/tools/dotnet-publish) command to build the app in release mode and create the assets in the *published* folder. |
| 49 | + |
| 50 | + ```dotnet |
| 51 | + dotnet publish -c Release -o published |
| 52 | + ``` |
| 53 | +
|
| 54 | +1. Create a file named *Dockerfile* in the directory containing your .csproj file, open it in a text editor, and enter the following content. A Dockerfile is a text file that doesn't have an extension and that is used to create a container image. |
| 55 | +
|
| 56 | + ```docker |
| 57 | + FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime |
| 58 | + WORKDIR /app |
| 59 | + COPY published/ ./ |
| 60 | + ENTRYPOINT ["dotnet", "TestAppConfig.dll"] |
| 61 | + ``` |
| 62 | +
|
| 63 | +1. Build the container by running the following command. |
| 64 | +
|
| 65 | + ```docker |
| 66 | + docker build --tag aspnetapp . |
| 67 | + ``` |
| 68 | +
|
| 69 | +## Create an Azure Container Registry instance |
| 70 | +
|
| 71 | +Create an Azure Container Registry (ACR). ACR enables you to build, store, and manage container images. |
| 72 | +
|
| 73 | +#### [Portal](#tab/azure-portal) |
| 74 | +
|
| 75 | +1. To create the container registry, follow the [Azure Container Registry quickstart](/azure/container-registry/container-registry-get-started-portal). |
| 76 | +1. Once the deployment is complete, open your ACR instance and from the left menu, select **Settings > Access keys**. |
| 77 | +1. Take note of the **Login server** value listed on this page. You'll use this information in a later step. |
| 78 | +1. Switch **Admin user** to *Enabled*. This option lets you connect the ACR to Azure Container Apps using admin user credentials. Alternatively, you can leave it disabled and configure the container app to [pull images from the registry with a managed identity](../container-apps/managed-identity-image-pull.md). |
| 79 | +
|
| 80 | +#### [Azure CLI](#tab/azure-cli) |
| 81 | +
|
| 82 | +1. Create an ACR instance using the following command. It creates a basic tier registry named *myregistry* with admin user enabled that allows the container app to connect to the registry using admin user credentials. For more information, see [Azure Container Registry quickstart](/azure/container-registry/container-registry-get-started-azure-cli). |
| 83 | +
|
| 84 | + ```azurecli |
| 85 | + az acr create |
| 86 | + --resource-group AppConfigTestResources \ |
| 87 | + --name myregistry \ |
| 88 | + --admin-enabled true \ |
| 89 | + --sku Basic |
| 90 | + ``` |
| 91 | +1. In the command output, take note of the ACR login server value listed after `loginServer`. |
| 92 | +1. Retrieve the ACR username and password by running `az acr credential show --name myregistry`. You'll need these values later. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Push the image to Azure Container Registry |
| 97 | + |
| 98 | +Push the Docker image to the ACR created earlier. |
| 99 | + |
| 100 | +1. Run the [az acr login](/cli/azure/acr#az-acr-login) command to log in to the registry. |
| 101 | + |
| 102 | + ```azurecli |
| 103 | + az acr login --name myregistry |
| 104 | + ``` |
| 105 | +
|
| 106 | + The command returns `Login Succeeded` once login is successful. |
| 107 | +
|
| 108 | +1. Use [docker tag](https://docs.docker.com/engine/reference/commandline/tag/) to tag the image appropriate details. |
| 109 | +
|
| 110 | + ```docker |
| 111 | + docker tag aspnetapp myregistry.azurecr.io/aspnetapp:v1 |
| 112 | + ``` |
| 113 | +
|
| 114 | + > [!TIP] |
| 115 | + > To review the list of your existing docker images and tags, run `docker image ls`. In this scenario, you should see at least two images: `aspnetapp` and `myregistry.azurecr.io/aspnetapp`. |
| 116 | +
|
| 117 | +1. Use [docker push](https://docs.docker.com/engine/reference/commandline/push/) to push the image to the container registry. This example creates the *aspnetapp* repository in ACR containing the `aspnetapp` image. In the example below, replace the placeholders `<login-server`, `<image-name>` and `<tag>` by the ACR's log-in server value, the image name and the image tag. |
| 118 | +
|
| 119 | + Method: |
| 120 | +
|
| 121 | + ```docker |
| 122 | + docker push <login-server>/<image-name>:<tag> |
| 123 | + ``` |
| 124 | +
|
| 125 | + Example: |
| 126 | +
|
| 127 | + ```docker |
| 128 | + docker push myregistry.azurecr.io/aspnetapp:v1 |
| 129 | + ``` |
| 130 | +
|
| 131 | +1. Open your Azure Container Registry in the Azure portal and confirm that under **Repositories**, you can see your new repository. |
| 132 | +
|
| 133 | + :::image type="content" border="true" source="media\connect-container-app\container-registry-repository.png" alt-text="Screenshot of the Azure platform showing a repository in Azure Container Registries."::: |
| 134 | +
|
| 135 | +## Add your container image to Azure Container Apps |
| 136 | +
|
| 137 | +Update your Container App to load the container image from your ACR. |
| 138 | +
|
| 139 | +1. In the Azure portal, open your Azure Container Apps instance. |
| 140 | +1. In the left menu, under **Application**, select **Containers**. |
| 141 | +1. Select **Edit and deploy**. |
| 142 | +1. Under **Container image**, click on the name of the existing container image. |
| 143 | +1. Update the following settings: |
| 144 | +
|
| 145 | + | Setting | Suggested value | Description | |
| 146 | + |----------------|----------------------------|----------------------------------------------------------------------------------| |
| 147 | + | Image source | *Azure Container Registry* | Select Azure Container Registry as your image source. | |
| 148 | + | Authentication | *Admin Credentials* | Use the admin user credential option that was enabled earlier in the container registry. If you didn't enable the admin user but configured to [use a managed identity](../container-apps/managed-identity-image-pull.md?tabs=azure-cli&pivots=azure-portal), you would need to manually enter the image and tag in the form. | |
| 149 | + | Registry | *myregistry.azurecr.io* | Select the Azure Container Registry you created earlier. | |
| 150 | + | Image | *aspnetapp* | Select the docker image you created and pushed to ACR earlier. | |
| 151 | + | Image tag | *v1* | Select your image tag from the list. | |
| 152 | +
|
| 153 | +1. Select **Save** and then **Create** to deploy the update to Azure Container App. |
| 154 | +
|
| 155 | +## Browse to the URL of the Azure Container App |
| 156 | +
|
| 157 | +In the Azure portal, in the Azure Container Apps instance, go to the **Overview** tab and open the **Application Url**. |
| 158 | +
|
| 159 | +The web page looks like this: |
| 160 | +
|
| 161 | +:::image type="content" border="true" source="media\connect-container-app\web-display.png" alt-text="Screenshot of an internet browser displaying the app running."::: |
| 162 | +
|
| 163 | +## Clean up resources |
| 164 | +
|
| 165 | +[!INCLUDE [Azure App Configuration cleanup](../../includes/azure-app-configuration-cleanup.md)] |
| 166 | +
|
| 167 | +## Next steps |
| 168 | +
|
| 169 | +In this quickstart, you: |
| 170 | +
|
| 171 | +- Connected Azure App Configuration to Azure Container Apps |
| 172 | +- Used Docker to build a container image from an ASP.NET Core app with App Configuration settings |
| 173 | +- Created an Azure Container Registry instance |
| 174 | +- Pushed the image to the Azure Container Registry instance |
| 175 | +- Added the container image to Azure Container Apps |
| 176 | +- Browsed to the URL of the Azure Container Apps instance updated with the settings you configured in your App Configuration store. |
| 177 | +
|
| 178 | +The managed identity enables one Azure resource to access another without you maintaining secrets. You can streamline access from Container Apps to other Azure resources. For more information, see how to [access App Configuration using the managed identity](howto-integrate-azure-managed-service-identity.md) and how to [[access Container Registry using the managed identity](../container-registry/container-registry-authentication-managed-identity.md)]. |
| 179 | +
|
| 180 | +To learn how to configure your ASP.NET Core web app to dynamically refresh configuration settings, continue to the next tutorial. |
| 181 | +
|
| 182 | +> [!div class="nextstepaction"] |
| 183 | +> [Enable dynamic configuration](./enable-dynamic-configuration-aspnet-core.md) |
0 commit comments