title | layout | sidebar | permalink | folder |
---|---|---|---|---|
Deploying a Docker based web application to Azure App Service |
page |
vsts2 |
/labs/vstsextend/docker/ |
/labs/vstsextend/docker/ |
A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
This lab outlines the process to build custom Docker images of an ASP.NET Core{:target="_blank"} application, push those images to a private repository in Azure Container Registry{:target="_blank"} (ACR). These images will be used to deploy the application to the Docker containers in the Azure App Service (Linux) using Azure DevOps.
The Web App for Containers allows the creation of custom Docker{:target="_blank"} container images, easily deploy and then run them on Azure. Combination of Azure DevOps and Azure integration with Docker will enable the following:
-
Build custom Docker images using Azure DevOps Hosted Linux agent{:target="_blank"}
-
Push and store the Docker images in a private repository
-
Deploy and run the images inside the Docker Containers
-
Refer the Getting Started page to know the prerequisites for this lab.
-
Click the Azure DevOps Demo Generator link and follow the instructions in Getting Started page to provision the project to your Azure DevOps.
-
Click on the Deploy to Azure button to initiate the configuration.
-
In Custom deployment window, select the Subscription type, leave the default selection for the resource group, and select the Location. Provide the Registry Name, Site Name, DB Server Name, accept the Terms and Conditions and click on the Purchase button to provision the following resources:
-
Azure Container Registry
-
Azure Web App for Containers
-
Azure SQL Server Database
{% include tip.html content= "Use lower case letters for DB Server Name" %}
{% include note.html content= " Registry name may contain alpha numeric characters only and must be between 5 and 50 characters." %}
{% include tip.html content= "At the time of writing this lab, the only location that can be used for the creation of ACR and SQL is SouthCentralUS." %}
-
-
It takes approximately 3 to 4 minutes to provision the environment. Click on Go to resource group to view the resource group.
-
The following components are provisioned post deployment.
-
Click on the mhcdb SQL database and make a note of the server details under the header Server name.
-
Navigate back to the resource group. Click on the container registry and make a note of the server details under the header Login server. These details will be required in the Exercise 2.
Now that the required resources are provisioned, the Build and the Release definition need to be manually configured with the new information. The dacpac will also be deployed to the mhcdb database so that the schema and data is configured for the backend.
-
Navigate to the Builds option under the Pipelines tab. Select the build definition
MHCDocker.build
, and select the Edit option. -
In the Run services, Build services and Push services tasks, authorize (only for the first task) the Azure subscription and update Azure Container Registry with the endpoint component from the dropdown and click on Save.
-
Navigate to the Releases section under the Pipelines tab. Select the release definition
MHCDocker.release
, click Edit Pipeline option and then click on the Tasks section. -
The usage details of the agents are provided below:
Agents Usage Details DB deployment The Hosted VS2017 agent is used to deploy the database Web App deployment The Hosted Ubuntu 1604 agent is used to deploy the application to the Linux Web App -
Under the Execute Azure SQL: DacpacTask section, select the Azure Subscription from the dropdown.
Execute Azure SQL: DacpacTask: This task will deploy the dacpac to the mhcdb database so that the schema and data are configured for the backend.
-
Under Azure App Service Deploy task, update the Azure subscription and Azure App Service name with the endpoint components from the dropdown.
Azure App Service Deploy will pull the appropriate docker image corresponding to the BuildID from repository specified, and then deploys the image to the Linux App Service.
-
Click on the Variables section, update the ACR details and the SQLserver details with the details noted earlier while the configuration of the environment and click on the Save button.
The Database Name is set to mhcdb, the Server Admin Login is set to sqladmin and the Password is set currently to P2ssw0rd1234.
In this exercise, the source code will be modified to trigger the CI-CD.
-
Click on Files section under the Repos tab, and navigate to the
Docker/src/MyHealth.Web/Views/Home
folder and open theIndex.cshtml
file for editing. -
Modify the text JOIN US to CONTACT US on the line number 28 and then click on the Commit button. This action would initiate an automatic build for the source code.
-
Click on Builds tab, you will see
MHCDoker.build
buils is queued. Double click on Build # or Commit to view the build in progress. -
The Build will generate and push the docker image of the web application to the Azure Container Registry. Once the build is completed, the build summary will be displayed.
-
Navigate to the Azure Portal{:target="_blank"} and click on the App Service that was created at the beginning of this lab. Select the Container Settings option and provide the information as suggested and then click the Save button.
Field Value to be provided Image Source Select the value Azure Container Registry Registry Select the registry value from the dropdown image Select the value myhealth.web Tag Select the value latest. This is required to map Azure Container Registry with the Web App. {% include tip.html content= "The Continuous Deployment can be configured to deploy the web app to the designated server whenever a new docker image is pushed to the registry on the Azure portal itself. However, setting up an Azure DevOps CD pipeline will provide better flexibility and additional controls (approvals, release gates, etc.) for the application deployment." %}
-
Navigate to the Azure Container registry created and then select the Repositories option to view the generated docker images.
-
Navigate to the Releases section under Pipelines tab, and double-click on the latest release displayed on the page. Click on Logs to view the details of the release in progress.
-
The release will deploy the docker image to the App Service based on the BuildID tagged with the docker image. Once the release is completed, the release Logs will be displayed.
-
Navigate back to the Azure Portal{:target="_blank"} and click on the Overview section of the App Service. Click on the link displayed under the URL field to browse the application and view the changes.
-
Use the credentials Username:
user
and Password:P2ssw0rd@1
to login to the HealthClinic web application.
With Azure DevOps and Azure, we have configured a dockerized application by leveraging docker capabilities enabled on Azure DevOps Ubuntu Hosted Agent.