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

Sample script

  1. Create a resource group

    az group create --name myResourceGroup --location westus
    
  2. 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
    
  3. Show ACR credentials

    az acr credential show --name <registry_name> --resource-group myResourceGroup --query [username,passwords[?name=='password'].value] --output tsv
    
  4. Before continuing, save the ACR credentials and registry URL. You will need this information in the commands below.

  5. Pull from Docker

    docker login <acr_registry_name>.azurecr.io -u <registry_user>
    docker pull <registry_user/container_name:version>
    
  6. Tag Docker image

    docker tag <registry_user/container_name:version> <acr_registry_name>.azurecr.io/<container_name:version>
    
  7. Push container image to Azure Container Registry

    docker push <acr_registry_name>.azurecr.io/<container_name:version>
    
  8. Create an App Service plan

    az appservice plan create --name AppServiceLinuxDockerPlan --resource-group myResourceGroup --location westus --is-linux --sku S1
    
  9. 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>
    
  10. 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.