Azure, Docker and a Web Application? Confusing but Possible

162 VIEWS

In the age of containerized applications, there are many cloud options to make building, running and storing your containers easier. Microsoft Azure is one such option. In this article, we’ll cover how to include a Docker container in the Azure Container Registry and how to use it in an Azure Web App for Containers.

Creating an Azure Container Registry

 

The first step is to create an Azure Container Registry service and add it to our account. There, we’ll save all our Docker containers. To do this, go to New, and search “Azure Container Registry.” On the screen (as shown in the screenshot below), just click Create.

On the next screen, you need to create a registry name that will be used as a URL (myregistryname.azurecr.io). Choose and type carefully—This name cannot be updated after creation.

Choose a subscription, a resource group and a location where your service will be running. I recommend you enable an administrator user for future management of the Azure Registry Container. (The Basic SKU is more than enough.) After filling in the information, just click on Create to finish this process.

Now, access the resource created to get the login server and keys to authenticate and include with your container. Copy the login server and click on Access keys.

Then, copy the registry name, the username and the password in a safe file to facilitate the next step in the command line.

How to include a Docker container in Azure

PS: Make sure you have Docker running on your computer before starting the next step.

Because the focus of the article is the configuration of the final environment, I’ll use a default NGINX image for Docker. To get this image, run:

docker pull nginx

Now, log into your Azure Container Registry with your username, password, and login server:

docker login –username mbcontainer –password as$2as$5das12 mbcontainer.azurecr.io

And then create a tag for the first version of your container:

docker tag nginx mbcontainer.azurecr.io/nginx:v1

Observe that the nomenclature is login-server/image-name.

Next, send the image to your Azure container:

docker push mbcontainer.azurecr.io/nginx:v1

When the push is complete, you can see your image and all tags under Repositories.

Great! And now, with the container in Azure, we’re ready to create a web application.

Creating a Web App Container

To create a Web App Container from Azure App Service, you need to go to New and search “Web App for Containers.” As indicated in the screenshot below, click on Create.

On the next screen, we need to define a name for the application, choose a subscription and a resource group, and an app service plan. (I usually prefer to create a separate app service plan for each application, because if I need to delete something, I can remove all resources associated.)

So, to create a new App Service Plan, click on the desired plan, and in the next panel, click on Create new. The next panel will show the options to create an App Service Plan. Fill in the name, and choose the location and the pricing tier. For most cases, the B1 Basic will be a good option.

Under the Configure container option, select Azure Container Registry in the Image source field. Then, your containers will appear. After selecting the right container, select the image and tag that will be used in your web application.

After completing these steps, click on OK in the Docker Container panel. To finish, simply click on Create within the Web App for Containers panel.

Access the created resource and copy the URL of your web application to test if everything works.

If you see the NGINX default page, this means that your web application is correct and pointed to your Docker container.

Conclusion

There are several steps in this process, which makes it especially rewarding to see the integration working. It amplifies the possibilities of delivering applications with private images, which previously required a private account with Docker Hub.

Keep in mind that you can configure your web app to update with every new push to your Docker image to guarantee continuous deployment.

Do you think you can beat this Sweet post?

If so, you may have what it takes to become a Sweetcode contributor... Learn More.

Software Engineer with experience in analysis and development of systems. Free software enthusiast and apprentice of new tech.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu