DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on • Updated on

Microsoft Azure Container Service

Make a Docker image and put it in an Azure Container Registry repository. To deploy a web application built using a Docker image, use Azure App Service. Create a webhook that checks for changes in the Docker image and uses it to configure continuous deployment for the web application.

A Microsoft Azure Container Service feature

  1. Quickly deploy to Azure
    Deploying web apps built on containers has never been simpler. Web App for Containers will quickly deploy the containerized app with your selected dependencies to production if you simply fetch container images from Docker Hub or a private Azure Container Registry. The platform handles load balancing, capacity provisioning, and OS patching automatically.

  2. Quicker ship updates
    Utilize the continuous integration/continuous deployment (CI/CD) features of Docker Hub, Azure Container Registry, and Visual Studio Team Services to automate and streamline your container image deployments. App Service establishes a connection to the chosen repository, ensuring that your apps are updated whenever your source code is modified. Plan performance and quality tests in the staging environment, and then use deployment slots to quickly switch from staging to production or revert to a previous version without affecting current users.

  3. Easily scale to meet needs
    Automatically adjust the horizontal and vertical scales to suit the needs of the application. Granular scaling rules are available to automatically handle workload peaks while lowering expenses when usage is low. With only a few mouse clicks, distribute data and hosting services across numerous locations.

Utilize the Azure Container Registry to create and store pictures.

You can put Docker images in the cloud in an Azure storage account using Azure Container Registry.
In the hypothetical example, the team has chosen to host their Docker images using Container Registry. Along with their other Azure resources, they may utilize Container Registry to create a Docker image registry in Azure where they can safely store their Docker images.
You'll discover more about Container Registry in this unit, including its benefits for storing Docker images.

Container Registry: What is it?

You can build your own personal Docker registries using the Azure feature known as Container Registry. Container Registry is structured similarly to Docker Hub around repositories that include one or more images. You may automate processes with Container Registry, like as redeploying an app once an image is rebuilt. You can build your own personal Docker registries using the Azure feature known as Container Registry. Container Registry is structured similarly to Docker Hub around repositories that include one or more images. You may automate processes with Container Registry, like redeploying an app once an image is rebuilt.

A key factor in choosing Container Registry over Docker Hub is security:

Who can view and utilize your photographs is considerably more under your control.
Images can be signed to boost confidence and lessen the possibility of them being maliciously or unintentionally corrupted.
In a container registry, all images are encrypted at rest.
Like using Docker Hub, working with images in Container Registry has a few advantages of its own:
Runs on Azure is Container Registry. To keep images close to where they will likely be deployed, the registry can be replicated.
The highly scalable Container Registry offers improved throughput for concurrent Docker pulls across several nodes. Container Registry's Premium SKU comes with 500 GiB of storage.

Apply the Container Registry

Either the Azure portal or the Azure CLI's acr create command are used to build registries. The new registry in the following code example is called my registry.

  • az acr create --name myregistry --resource-group mygroup --sku standard --admin-enabled true

You may use Container Registry to create images in addition to hosting and storing them. Use the CLI to upload the Docker file and additional files that make up your image rather than creating an image from scratch and uploading it to the Container Registry. Following that, Container Registry will create the image for you. Run a build by using the acr build command.

  • _az acr build --file Dockerfile --registry myregistry --image myimage _

Build and store an image using Azure Container Registry as an exercise.

The Azure Container Registry offers cloud storage for Docker images.
In the hypothetical example, the group must set up a registry to house the photos for their web apps.
In this lesson, you'll learn how to build a new registry in the Container Registry using the Azure interface. A web application's source code will be used to create a Docker image, which you will then upload to a repository in your registry. The registry and repository's contents will next be examined.

Create a registry in Azure Container Registry

  1. Utilize your Azure subscription to log in to the Azure portal.
  2. Choose Create a resource from the list of Azure services on the Azure portal's home page. The resource creation pane appears.
  3. Select Containers from the left menu pane, then click Container Registry under Popular Azure Services.

Image description

A pane labelled Create Container Registry appears.
Enter the corresponding values for each parameter in the Basics tab.

Image description

Create a Docker image, then submit it to the Azure Container Registry.

Run the following command to get the source code for the sample web app in Azure Cloud Shell on the portal (choose the first icon on the upper toolbar). The web app is straightforward. The interface consists of a single page with static text and a carousel control that cycles through a number of photos.

  • git clone https://github.com/MicrosoftDocs/mslearn-deploy-run-container-app-service.git
    Move to the source folder.

  • cd mslearn-deploy-run-container-app-service/dotnet
    Execute the next command. This command delivers the contents of the folder to the Container Registry, which creates and stores the image according to the directions in the Docker file. The name of the registry you previously built should be substituted for container registry name>. Don't forget to add the. character to the command's end.

  • az acr build --registry --image webimage

The Docker file includes detailed instructions for creating a Docker image from the web app's source code. These actions are carried out by Container Registry to create the picture, and a message is produced after each action is finished. After a few minutes, the construction procedure ought to be finished without any issues or cautions.

Take a look at the container registry.

  1. Go back to the Azure interface and click Go to the resource on the Overview page for your container registry. A pane for your Container registry displays.

  2. Select Repositories from the Services section of the left menu pane. Your container registry's Repositories pane appears. You'll find the web image repository.

  3. Choose the online image archive. The repository pane for websites appears. It includes a picture with the newest tag. This is the sample web app's Docker image.

Image description

Complete the deployment of a web application using an image from the Azure Container Registry repository.

  1. A web app can be simply deployed from Azure Container Registry to Azure App Service.
  2. The team intends to host the web application on App Service in the sample scenario. To retrieve the image for the web app from the repository in Container Registry, they must configure App Service.
  3. You will discover how to set up App Service to deploy a web app from a repository in Container Registry in this unit.

Deploy a web application from an Azure Container Registry repository.

The following properties are set while building a web application from a Docker image:

  1. Registry where the picture is stored: The registry could be Container Registry, Docker Hub, or some other kind of personal registry.
  2. The repository's name is shown in the accompanying image.
  3. Tag: This item specifies which repository version of the picture should be used. By custom, when a version is built, the tag latest is applied to the most recent version.
  4. Startup file: The name of an executable file or a command to be executed when the image is loaded is contained in this item. It is comparable to the command that you can enter into Docker to load an image when using the docker run command. You don't need to fill this out if you're deploying a containerized app that is already configured with the ENTRYPOINT and/or COMMAND settings. The Docker image is retrieved and launched as a cold start operation the first time a user tries to access the website after the web app has been configured. The app could take a few seconds to launch at first, but once it does, it will be accessible right away.

Web application deployment from an Azure Container Registry repository

The hosting environment for an Azure-based web app is provided by Azure App Service. You can set up App Service to get the web app's image from an Azure Container Registry repository.
In the hypothetical example, the team has already uploaded the web app's image to Azure Container Registry and is now prepared to launch it.
By utilizing the Docker image that is kept in the Azure Container Registry, you will develop a new web application in this unit. The web app will be hosted by App Service using a specified App Service plan.

Open the Azure Container Registry to Docker

Using Docker, you'll access the registry and get the web image you wish to deploy. For this task, Docker requires a login and password. To allow Docker to log into your container registry, you can use the Container Registry to configure the registry name as the username and the admin access key as the password.

  1. Navigate to All resources after signing into the Azure portal. The pane for all resources appears.
  2. To access the Overview page of the container registry you previously built, select it.
  3. Select Access keys from the Settings menu on the left. The Container Registry's Access keys pane appears.
  4. Turn on the admin user setting. This modification automatically saves.
  5. You can now start building your web application.

Create a web app

Return to the home page of the Azure portal and click Create a resource under Azure services. The resource creation pane appears.
Select Web from the left menu pane, then click Web App under Popular Azure services.

Image description

The pane for creating Web apps appears.
Enter the corresponding values for each parameter in the Basics tab.

Image description
Next, pick Docker.
Enter the corresponding values for each setting under the Docker tab.

Image description
Select Create, then choose Review and create. Before moving on, wait until the web application has been deployed.

Test the online application.

  1. When the deployment is successful, choose Go to resource to view the newly generated web app. Your web app's App service pane appears.

  2. To access the website in a new browser tab, choose Browse from the top menu bar.
    You'll see a page similar to the one in the following image after the cold start wait during which your app's Docker image loads and launches.

Image description

Redeploy the web application automatically after updating the image Completed

For many dynamic firms, continuous deployment is a crucial component. They must swiftly yet quietly deploy the most recent version of their software.
In the case study, the web app's development team frequently adds new features and improvements. The team has chosen to use a continuous-deployment strategy as a result.
You will set up the continuous deployment of a web application that makes use of an image in the Azure Container Registry in this section.

What is a webhook?

Webhooks are used to allow continuous deployment in Azure App Service. The service provided by Container Registry is a webhook. Services and programs can sign up for the webhook to receive notifications when photos in the registry are updated. A web app that makes use of App Service can sign up for a Container Registry webhook to receive alerts when the image containing the web app is updated. Your app restarts the site and fetches the most recent version of the picture when the image is updated, and App Service receives a notification.

What is the Azure Container Registry tasks feature?

Utilizing webhooks, Azure App Service allows continuous deployment. Container Registry provides a webhook service. To be notified when photos in the registry are updated, services and apps can subscribe to the webhook. A web app that makes use of App Service has the option to sign up for updates to the image containing the web app by subscribing to a Container Registry webhook. Your app immediately refreshes the site and downloads the most recent version of the picture when App Service receives a notification that the image has been updated.
Let's use these two features to enable continuous integration from the App Service.

Enable continuous integration from App Service

The configuration of continuous integration is automated on the Container settings page of an App Service resource in the Azure portal. App Service configures a webhook in your container registry to alert an App Service endpoint if Continuous Deployment is enabled. Your programmed restarts and downloads the most recent container image when notifications from the registry reach this endpoint.
Extend continuous integration to source control by using an Azure

Container Registry task

Tasks for the Container Registry can only be generated via the command line. The az acr task creates a command that creates and registers a long-lived task, as opposed to the az acr build command that we used to construct our image previously.
The command that follows demonstrates how to create a task called "construct a web app." The task keeps track of this module's sample web app's GitHub repository. The task creates the web image Docker image from the GitHub source code each time a change is committed and stores it in your registry in Container Registry. You must first create a GitHub personal access token with the ability to add a webhook to your repository before executing this command. The token will also require full repository read access for private repositories.

_az acr task create --registry --name buildwebapp --image webimage --context https://github.com/MicrosoftDocs/mslearn-deploy-run-container-app-service.git --file Dockerfile --git-access-token
_

Exercise: Change the image and deploy the web application again

You will set up continuous deployment for the web app in this unit and make a webhook that connects to the registry that houses the Docker image. The web app's source code will then be modified, and the image will be rebuilt. You'll return to the website that houses the sample web app and check to see if the most recent version is active.

  1. Establish a webhook and configure continuous deployment
  2. Select your web app by going back to the Azure site. Your web app's App service pane appears.
  3. Select Deployment Center from the Deployment menu on the left. Your app service's Deployment Center pane appears (web app).
  4. Set Continuous Deployment to On in the Registry settings section of the Settings page, then choose Save in the top menu bar. The webhook that Container Registry uses to notify the web app that the Docker image has changed is configured via this parameter.

Image description
Webhook testing and web app updates
Navigate to the dotnet/SampleWeb/Pages folder in Azure Cloud Shell. The HTML source code for the pages that the web application displays is located in this folder.

  • cd ~/mslearn-deploy-run-container-app-service/dotnet/SampleWeb/Pages
    Run the following instructions to create a new version of the web app's default page (Index.cshtml) that includes one extra item in the carousel control. These instructions add a new page to the carousel while simulating the app's ongoing development.

  • mv Index.cshtml Index.cshtml.old

  • mv Index.cshtml.new Index.cshtml

Execute the following commands to recreate the web app's image and push it to the Container Registry. Substitute your registry's name for container registry name>. At the conclusion of the second command, don't forget the.

  • cd ~/mslearn-deploy-run-container-app-service/dotnet

  • az acr build --registry --image webimage
    Go back to the home page of the Azure interface and choose your container registry under Recent resources. A pane for your Container registry displays.
    Select Webhooks from the Services section of the left menu pane. The Webhooks window for your container registry becomes visible.
    Choose the lone webhook from the list. The webhook for your container registry displays.
    Take note of the webhook record that just fired in response to your build and push.

Image description
T

Test the web app again

Return to your web application in the browser. You might navigate to the Overview page of the app in the Azure portal and choose to Browse if you previously closed the tab for it. While the web application loads the updated image from Container Registry, there will be a cold start delay.
Look over the things on the carousel control. Take note that there are now four pages in the control. The updated page resembles the illustration below.

Image description
Docker images can be stored in Azure Container Registry, and web apps can be built using these images. You may set up continuous deployment for a web app by using a webhook. This process keeps an eye on the web app's image in Container Registry and will immediately redeploy the web app if the image changes

Top comments (0)