Events
Mar 17, 11 p.m. - Mar 21, 11 p.m.
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure DevOps enables you to host, build, plan, and test your code with complimentary workflows. Using Azure Pipelines as one of these workflows allows you to deploy your application with CI/CD that works with any platform and cloud. A pipeline is defined as a YAML file in the root directory of your repository.
In this article, we use Azure Pipelines to deploy a Windows container application to App Service from a Git repository in Azure DevOps. It assumes you already have a .NET application with a supporting dockerfile in Azure DevOps.
Before you create your pipeline, you should first create your Service Connection since you'll be asked to choose and verify your connection when creating your template. A Service Connection allows you to connect to your registry of choice (ACR or Docker Hub) when using the task templates. When adding a new service connection, choose the Docker Registry option. The following form asks you to choose Docker Hub or Azure Container Registry along with pertaining information. To follow along with this tutorial, use Azure Container Registry. You can create a new Service Connection following the directions here.
Since we're using sensitive information that you don't want others to access, we use variables to protect our information. Create a variable by following the directions here.
To add a Variable, you click the Variables button next to the Save button in the top-right of the editing view for your pipeline. Select the New Variable button and enter your information. Add the variables below with your own secrets appropriate from each resource.
Once your repository is created with your .NET application and supporting dockerfile, you can create your pipeline following these steps.
After your pipeline is created and saved, you'll need to edit the pipeline to run the steps for building the container, pushing to a registry, and deploying the image to App Service. To start, navigate to the Pipelines menu, choose your pipeline that you created and click the Edit button.
First, you need to add the docker task so you can build the image. Add the following code and replace the Dockerfile: app/Dockerfile with the path to your Dockerfile.
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
vmImageName: 'windows-latest'
imageRepository: 'your-image-repo-name'
dockerfilePath: '$(Build.SourcesDirectory)/path/to/Dockerfile'
dockerRegistryServiceConnection: 'your-service-connection-number'
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build job
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)
Next, you need to set up the deploy task. This requires your subscription name, application name, and container registry. Add a new stage to the yaml file by pasting the code below.
- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
steps:
Next, navigate to the Show assistant tab in the upper right hand corner and find the Azure App Service deploy task and fill out the following form:
Once you have those filled out, click the Add button to add the task below:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'my-subscription-name'
appType: 'webAppHyperVContainer'
WebAppName: 'my-app-name'
DockerNamespace: 'myregsitry.azurecr.io'
DockerRepository: 'dotnetframework:12'
After you've added the task the pipeline is ready to run. Click the Validate and save button and run the pipeline. The pipeline goes through the steps to build and push the Windows container image to Azure Container Registry and deploy the image to App Service.
Below is the example of the full yaml file:
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
vmImageName: 'windows-latest'
imageRepository: 'your-image-repo-name'
dockerfilePath: '$(Build.SourcesDirectory)/path/to/Dockerfile'
dockerRegistryServiceConnection: 'your-service-connection-number'
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build job
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)
- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
steps:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'my-subscription-name'
appType: 'webAppHyperVContainer'
WebAppName: 'my-app-name'
DockerNamespace: 'myregsitry.azurecr.io'
DockerRepository: 'dotnetframework:12'
Events
Mar 17, 11 p.m. - Mar 21, 11 p.m.
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Automate Docker container deployments with Azure Pipelines - Training
Use Azure Pipelines to deploy Docker containers to Azure App Service.
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.