Deploy to Azure Web App for Containers
Use App Service on Linux and pipelines to deploy your web app to a custom container in Azure. In this quickstart, you'll use Azure Pipelines to build and deploy a sample application to an App Service custom container.
With Azure Pipelines, you can implement a CI/CD workflow to automatically generate build artifacts and trigger deployment to specific environments.
- An Azure account with an active subscription. Create an account for free.
- A GitHub account. Create a free GitHub account if you don't have one already.
- An Azure Container Registry. Create an Azure container registry if you don't have one already.
Get the code
Build and publish a Docker image to an Azure Container Registry
To complete this section successfully, you must have an Azure Container Registry. Refer to the prerequisites section for details.
Sign in to your Azure DevOps organization and navigate to your project.
Select Pipelines, and then New Pipeline.
Select GitHub when prompted for the location of your source code, and then select your repository.
Select the Docker: build and push an image to Azure Container Registry pipeline template.
Select your Azure subscription, and then select Continue.
Select your Container registry from the drop-down menu, and then select Validate and configure.
Review the pipeline YAML template, and then select Save and run to build and publish the Docker image to your Azure Container Registry.
To view the published Docker image after your pipeline run has been completed, navigate to your container registry in Azure portal, and then select Repositories.
To deploy your image from the container registry, you must enable the admin user account. Navigate to your container registry in Azure portal, and select Access keys. Next, select the toggle button to Enable Admin user.
Create your Web App for Containers
Sign into Azure at https://portal.azure.com.
In the Azure portal, choose Create a resource > Containers, and then choose Web App for Containers.
Enter a name for your new web app, and select or create a new Resource Group. Select Linux for the Operating System.
In the SKU and Size section, select Change to specify the pricing tier. Select the Dev/Test plan, and then choose the F1 Free plan. Select Apply when you are done.
Select Review and create. Review your configuration, and select Create when you are done.
Deploy with the Azure Web App for Container task
Deploy to an Azure App custom container with the Azure Web App for Container task
trigger: - main resources: - repo: self variables: ## Add this under variables section in the pipeline azureSubscription: <Name of the Azure subscription> appName: <Name of the Web App> containerRegistry: <Name of the Azure container registry> dockerRegistryServiceConnection: '4fa4efbc-59af-4c0b-8637-1d5bf7f268fc' imageRepository: <Name of image repository> dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile' tag: '$(Build.BuildId)' vmImageName: 'ubuntu-latest' stages: - stage: Build displayName: Build and push stage jobs: - job: Build displayName: Build pool: vmImage: $(vmImageName) steps: - task: Docker@2 displayName: Build and push an image to container registry inputs: command: buildAndPush repository: $(imageRepository) dockerfile: $(dockerfilePath) containerRegistry: $(dockerRegistryServiceConnection) tags: | $(tag) ## Add the below snippet at the end of your pipeline - task: AzureWebAppContainer@1 displayName: 'Azure Web App on Container Deploy' inputs: azureSubscription: $(azureSubscription) appName: $(appName) containers: $(containerRegistry)/$(imageRepository):$(tag)
The Azure Web App on Container task will pull the appropriate Docker image corresponding to the BuildId from the repository specified, and then deploy the image to your Azure App Service on Linux.
Deploy to a slot
You can configure the Azure Web App container to have multiple slots. Slots allow you to safely deploy your app and test it before making it available to your customers.
The following YAML snippet shows how to deploy to a staging slot, and then swap to a production slot:
- task: AzureWebAppContainer@1 inputs: azureSubscription: '<Azure service connection>' appName: '<Name of the web app>' containers: $(containerRegistry)/$(imageRepository):$(tag) deployToSlotOrASE: true resourceGroupName: '<Name of the resource group>' slotName: staging - task: AzureAppServiceManage@0 inputs: azureSubscription: '<Azure service connection>' WebAppName: '<name of web app>' ResourceGroupName: '<name of resource group>' SourceSlot: staging SwapWithProduction: true
How do I find my registry credentials for the web app?
App Service needs information about your registry and image to pull the private image. In the Azure portal, go to Configuration for the web app and update your Docker information.