Jump to content

Host and Deploy Images on Azure Container Registries (ACR) via App Service - A step-by-step guide


Recommended Posts

Guest suzarilshah
Posted

Learn how to host images on Azure Container Registry and deploy a Web App via the App Service plan. A step-by-step guide by Suzaril Shah

 

 

 

Welcome to my latest blog post! I'm Suzaril Shah, a Gold Microsoft Learn Student Ambassador, and today I'm excited to share a detailed, step-by-step guide on how to efficiently host your images on Azure Container Registry (ACR) and deploy a web application using an App Service plan. Whether you're a developer, IT professional, or just a tech enthusiast looking to expand your Azure knowledge, this guide is designed to walk you through the process seamlessly. From setting up your ACR to deploying your app, I'll cover all the necessary steps and best practices to ensure you can get your web app up and running with ease. Let's dive in and start deploying on Azure!

 

 

 

[HEADING=1]Prerequisites:[/HEADING]

[HEADING=1]Step 1 - Prepare the Docker Container[/HEADING]

 

For this demonstration, I cloned this Docker Hub Image and tagged the image to my own Docker Hub account. This image particularly contains web pages, which is useful to display that the web app is served and accessible via the internet. However, if you have your own Docker image, feel free to use them.

 

 

 

616x317vv2.png.f9fca7d54be626b4b542da40d199ac95.png

 

 

 

[HEADING=1]Step 2 - Setting the Container Registry on Azure[/HEADING]

 

Go to Azure Portal (portal.azure.com) and search for “Container Registries” on the Search bar and click on it. Create a new registry by clicking on the “+ Create” button.

 

 

 

485x159vv2.png.dce0989853d504bb248818554af7998e.png

 

 

 

Select your Subscription and Resource Group from the dropdown and name your registry.

 

 

 

436x494vv2.png.1661893f52859bbb2a74d5f335fe72dc.png

 

 

 

Click on “Next >” button until you have reached the “Review + create”. Click on “Create” button to finalize the registry creation.

 

 

 

422x532vv2.png.45e3b71a13723981d9be348e861edb68.png

 

 

 

Once the Deployment is complete, click on the “Go to resource” button to view the registry. At this point the registry is ready to store the image in the registry.

 

mediumvv2px400.png.65f1c1bb0a00dbf30decd3481bae223f.png

 

 

 

[HEADING=2]Enable Admin user on the Azure Container Registry[/HEADING]

 

Each container registry includes an admin user account, which is disabled by default. You can enable the admin user and manage its credentials in the Azure portal, or by using the Azure CLI, Azure PowerShell, or other Azure tools. The admin account has full permissions to the registry.

 

 

 

To enable Admin user, you can go to the container registry page you have created earlier and head to “Settings” > “Access Keys” subsection. Click on the checkbox for “Admin User”. Two passwords should be generated.

 

 

 

664x227vv2.png.ea7e29d856a9ce40f5733d8e14fc13e0.png

 

[HEADING=1]Step 3 - Push image to Azure container registry from Docker Hub[/HEADING]

 

On the Azure Container Registry page, click on the “Push an Image” button to get started with the hosting the image on Azure registry.

 

 

 

757x237vv2.png.254f66bc6e24feb85c3bc7c7a3f64077.png

 

 

 

Follow the instructions given on Azure to login, pull & tag image to ACR and push the image to the Azure registry.

 

[HEADING=2]

Login to Azure on a CLI.[/HEADING]

 

 

 

 

 

[iCODE]az login[/iCODE]

 

 

 

 

 

Upon logging in to Azure via CLI, you should be redirected to complete browser authentication and see this page:

 

636x213vv2.png.7e0eb3479c60b26cb043f06c7f80f2d4.png

 

 

 

Now login to your Azure Container registry

 

 

 

 

 

[iCODE]az acr login --name [REGISTRY_NAME][/iCODE]

 

 

 

 

 

You should receive an output resembling the following:

 

 

 

 

 

az acr login --name suzarilshah
Login Succeeded

 

 

 

 

 

[HEADING=2] [/HEADING]

[HEADING=2]Pull the image on Docker Hub and tag the image to ACR.[/HEADING]

 

Now pull an image to your host machine so we can prepare and host them on Azure Container Registry. In this case, I will use the image in Step 1.

 

 

 

 

 

docker pull airilshahz/apptest
Using default tag: latest
latest: Pulling from airilshahz/apptest
59bf1c3509f3: Pull complete
683dd8c3cc08: Pull complete
ae5b2724f19b: Pull complete
39190df3f477: Pull complete
dd3448b85aa1: Pull complete
d73408ac8b5c: Pull complete
26a6466d7ac5: Pull complete
3db399cf7250: Pull complete
Digest: sha256:249cb92c030c02d5a13b1beef894c306e77aa82e6847e7fc04d2ec46f8306579
Status: Downloaded newer image for airilshahz/apptest:latest
docker.io/airilshahz/apptest:latest

What's Next?

 View a summary of image vulnerabilities and recommendations → docker scout quickview airilshahz/apptest

 

 

 

 

 

 

 

Let’s tag the image following the tag format: [REGISTRY_ENDPOINT/REPOSITORY/IMAGE]. You can find the Registry Endpoint at the ACR Overview page (Login server)

 

 

 

 

 

[iCODE]docker tag airilshahz/apptest suzarilshah.azurecr.io/webapp/apptest[/iCODE]

 

 

 

 

 

[HEADING=2] [/HEADING]

[HEADING=2]Push the Image on Azure Container Registry[/HEADING]

 

 

 

 

 

docker push suzarilshah.azurecr.io/webapp/apptest
Using default tag: latest
The push refers to repository [suzarilshah.azurecr.io/webapp/apptest]
177b596a6349: Pushed
9707d450e65b: Pushed
5bcf0d6dff6a: Pushed
1b6b342bd971: Pushed
49281578ca1a: Pushed
c833154f20e9: Pushed
5be440dc5019: Pushed
8d3ac3489996: Pushed
latest: digest: sha256:249cb92c030c02d5a13b1beef894c306e77aa82e6847e7fc04d2ec46f8306579 size: 1998

 

 

 

 

 

 

 

Now you have an image stored on Azure Container Registry. You can check the image you pushed on ACR by going to the “Services” > “Repositories” section on the ACR page.

 

 

 

755x358vv2.png.7506e4927c82b394a04d5fd373b3eb47.png

 

 

 

[HEADING=1]Step 4 - Deploy the Image to App Service from ACR[/HEADING]

 

Head to “App Service” by searching for them on the Search bar on Azure portal. Click on the “+ Create” > “Web App” button to create a Web App.

 

 

 

440x144vv2.png.9c6d560970400a65635b5e53658ef8d3.png

 

 

 

Select Subscription from the drop down menu and specify the resource group. Then, name your web app endpoint. Follow the configuration as specified below. Please ensure that you have selected “Container” for the “Publish” configuration.

 

 

 

595x409vv2.png.71daa72bd05826e04526e1b2105a6b50.png

 

 

 

Create a new Linux Plan under the “Pricing plans” section. For this demonstration, I will use the Free tier to host my web app. Then, click on Next to proceed with creating the web app.

 

 

 

543x309vv2.png.fb6f8dcbf625ba8ca302888faaa39d25.png

 

 

 

On the “Container” tab, make sure to Select “Azure Container Registry” as the Image Source. Select the Registry you have created earlier and specify the Image and Tag.

 

 

 

525x551vv2.png.705b5915a7100c539dc29c9c1a70e1ab.png

 

 

 

On the “Networking” tab, please make sure to turn on the “Enable public access” settings. This ensures that our web app is accessible to everyone on the Internet. Turn this off, if you do not intend to allow external users to access your web app.

 

 

 

603x296vv2.png.060b734e169a5cfaa011f29b53382496.png

 

 

 

Click on the “Review + create” button to finalize the Web App configuration. Click on “Create” button to deploy the web app.

 

 

 

416x464vv2.png.ceed9233697d75ec176b42ea4833a625.png

 

 

 

 

 

After the Web App is deployed successfully, click on the “Go to resource” button to view the Web App overview page.

 

 

 

mediumvv2px400.png.b01b4109c2ea8abc56b4915f1f507f91.png

 

 

 

To view your Web App, click on the “Browse” button on the Web App overview page or copy and paste the information from the “Default domain” section to access your web app.

 

 

 

900x126vv2.png.ba84f5cef7483338fd5437ea407e79e0.png

 

 

 

Voila! The Web App is now accessible on the Internet.

 

 

 

[HEADING=2]704x371vv2.png.d7b14138164d71f7c2cf008f4985d069.png

 

Learning takeaways[/HEADING]

 

This comprehensive guide provides a detailed walkthrough on using Azure Container Registry (ACR) and Azure App Service to host and deploy web applications. Readers should be able to set up ACR, host images to ACR, and deploy the images hosted on ACR via App Service. This tutorial not only enhances technical skills in managing cloud-based applications but also offers practical insights into integrating and leveraging Azure services to publish applications on the internet.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...