Create an ASP.NET Core app in a Docker container in App Service from Azure Container Registry
This sample script creates a resource group, a Linux App Service plan, and an app. It then deploys an ASP.NET Core application using a Docker Container from the Azure Container Registry.
If you don't have an Azure subscription, create an Azure free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Sample script
Create a resource group
az group create --name myResourceGroup --location westus
Create an Azure Container Registry
az acr create --name <registry_name> --resource-group myResourceGroup --location westus --sku basic --admin-enabled true --query loginServer --output tsv
Show ACR credentials
az acr credential show --name <registry_name> --resource-group myResourceGroup --query [username,passwords[?name=='password'].value] --output tsv
Before continuing, save the ACR credentials and registry URL. You will need this information in the commands below.
Pull from Docker
docker login <acr_registry_name>.azurecr.io -u <registry_user> docker pull <registry_user/container_name:version>
Tag Docker image
docker tag <registry_user/container_name:version> <acr_registry_name>.azurecr.io/<container_name:version>
Push container image to Azure Container Registry
docker push <acr_registry_name>.azurecr.io/<container_name:version>
Create an App Service plan
az appservice plan create --name AppServiceLinuxDockerPlan --resource-group myResourceGroup --location westus --is-linux --sku S1
Create a web app
az webapp create --name <app_name> --plan AppServiceLinuxDockerPlan --resource-group myResourceGroup --deployment-container-image-name <acr_registry_name>.azurecr.io/<container_name:version>
Configure an existing web app with a custom Docker Container from Azure Container Registry.
az webapp config container set --resource-group myResourceGroup --name <app_name> --docker-registry-server-url http://<acr_registry_name>.azurecr.io --docker-registry-server-user <registry_user> --docker-registry-server-password <registry_password>
Clean up resources
Use the following command to remove the resource group and all resources associated with it using the az group delete command - unless you have an ongoing need for these resources. Some of these resources may take a while to create, as well as to delete.
az group delete --name $resourceGroup
Sample reference
This script uses the following commands to create a resource group, App Service app, and all related resources. Each command in the table links to command specific documentation.
Command | Notes |
---|---|
az group create |
Creates a resource group in which all resources are stored. |
az appservice plan create |
Creates an App Service plan. |
az webapp create |
Creates an App Service app. |
az webapp config container set |
Sets the Docker container for the App Service app. |
Next steps
For more information on the Azure CLI, see Azure CLI documentation.
Additional App Service CLI script samples can be found in the Azure App Service documentation.