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.

You need Azure CLI version 2.0.52 or later. To find the version, run az --version. If you need to install or upgrade, see Install the Azure CLI.

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 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 deployment

After the sample script has been run, the following command can be used to remove the resource group and all resources associated with it.

az group delete --name myResourceGroup

Script explanation

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.