How to Create a Docker Container Image on Azure

One of the most exciting technology trends that emerged in the recent pandemic is the rise of investment in cloud services and Docker containers. Enterprises actively put in their resources to form cloud strategies that utilize one or even more cloud services such as Docker or Azure Container Registry. Such strategies come in many flavors, like hybrid or multi-cloud, but all promise enterprises the most advanced features for the next decade or so to come.

The availability of many cloud services gives enterprises to choose the one(s) that best suit their strategy and resources. Today, from a small-time startup to a multinational corporation, everyone can use the cloud to their advantage. Among the top cloud services currently is Microsoft Azure, and its popularity comes from its massive range of tools and services. Azure can come in handy no matter the requirement, like training machine learning models or using a container technology like Docker.

This article tackles the question of bringing Docker to Azure and using Azure’s built-in services to build a container image. It will briefly discuss Azure, the possibilities it offers, and then explain the image-building process in detail.

Create Docker Container image on Azure

Unlocking The Potential Of Cloud With Microsoft Azure

Azure is Microsoft’s suite of cloud based services and software intended to be a one-stop place for doing everything from building to deploying and testing applications. Launched back in 2010, Microsoft started the services off and added more robust ones as time passed. Azure services now also include AI model training and high-level warehousing and analytics. Today, Microsoft offers Azure services on a subscription basis and individual access as well.

As a whole entity on its own, Azure can take multiple forms for different enterprises. Some can use its infrastructure-as-a-service (IaaS) model, while some can utilize its software-as-a-service nature (SaaS). Microsoft has built integral security features like data recovery and constant backups for the kind of workload Azure is intended to maintain. Users can also use Azure’s server space to host their applications once they are set to go into the production phase.

One of the most prominent features of Microsoft Azure is its readiness to provide developers the opportunity to develop new and coming technologies. The recent spike in interest in IoT, 5G, and hybrid personal computing has led to Microsoft including services centered around these technologies. Examples like the Azure IoT Hub and Windows 365 Cloud PC show that Microsoft doesn’t want to be left behind when these robust technologies grow common.

Docker images on azure

Some of the most commonly mentioned strengths of Microsoft Azure throughout the industry are as follows:

  • Flexibility: Azure offers its services to all different levels of enterprises. Once signed up, an enterprise can plan to scale and grow further within Azure’s environment without any hassle. On the contrary, an enterprise wanting to adjust its resources due to a shrinking budget is accommodated by Azure too. 

 

  • Security: Azure offers many security features. Its massive data centers enable backing up vast volumes of data, and services like Azure Site Recovery let Azure take care of all the backing up and securing for you. Azure Site Recovery also integrates easily with Hyper-V architecture and System Center. 

 

  • Augmenting Active Directory Functionalities: Active Directory is one of the most commonly used authentication and authorization mechanisms in networks. By implementing AD on Azure, users can bring perks like centralized management and powerful security to a global and far-reaching scope. Azure’s support for multi-level authentication helps add an extra layer of protection along with AD’s security level. 

 

  • Economical: With so much to offer, Azure still has a relatively economical pricing strategy. It is intended to be flexible and inclusive of all levels, from individual developers to full-fledged companies. Even Azure’s operational costs are also famously low.

The wide popularity of technologies like Docker on Azure and other container technologies have resulted in many applications on the internet built using Docker containers. 

Using Azure Container Registry to Create Docker Images on Azure

Microsoft Azure is one of the most preferred choices among the cloud services available today. Its support for all popular development tools makes it a leading choice for enterprises to invest in to aid their development teams. Azure offers a wide range of dedicated services for running or configuring the development tools, like the Azure Container Registry (ACR).

Container technology is increasingly becoming a staple for all kinds of software development. Azure’s ACR service provides its users an easy way to automate building and maintaining container images without ever leaving Azure’s environment. When it comes to using the most popular container technology Docker on Azure and creating its container images, users can utilize ACR Tasks.

Discussed below is the process of using ACR tasks and Azure’s command-line interface (CLI). We will be creating a registry for the container, use a Dockerfile to build, and then push the image. All the other relevant tools used for the process are also explained and mentioned below.

You will be using the Bash environment inside Azure Cloud Shell and the Azure CLI to run the relevant commands without any hassle.

Create Azure Container Registry

The process is as given below:

 

  • Creating a resource group: You will need to create a container registry if you don’t have a preexisting one. Before that, we need to create a ‘resource group.’ It is an environment for deploying and managing Azure resources.

 

Use the following command to create a resource group. For this example, we are naming it myTestResource. The location specifies the geographical area to ensure the best server availability.

				
					az group create --name myTestResource --location eastus
				
			
  • Creating a registry: Once we have a resource group to work in, we now create a container registry. The following command creates a cost-optimized Basic registry option for developers learning ACR (shown below).
create Azure Container Registry

Note that the name for the registry has to be unique and has 5-50 alphanumeric characters.

				
					az acr create --resource-group myTestResource \
  --name myTestRegistry009 --sku Basic
				
			

Create Docker Container Image on Azure

  • Building an image from a Dockerfile & Pushing It: Now that the technical prerequisites for building a Docker container in Azure are out of the way, we will move onto the container image itself. We will use ACR to make the Dockerfile that configures the container image. Our example utilizes a premade container image available at Microsoft Container Registry. You can create your own or get the relevant one from Docker Hub.

    Within a Bash shell, the following command fetches the hello-world container image and puts it in a file called Dockerfile.
				
					echo FROM mcr.microsoft.com/hello-world > Dockerfile
				
			

Afterward, the following command shall build the image and push it to our registry. As visible, it specifies the name and version of the container image, our registry, and the exact Dockerfile to be built by ACR. The . at the very end of the last line signifies the file’s location, which is the current working directory in this case.

				
					az acr build --image sample/test-container:v1 \
  --registry myTestRegistry009 \
  --file Dockerfile .
				
			

We have our container built and pushed to the registry. In case you want to run the image and build a container, you can use the az acr run command. After we build the container image and get our container, we can safely delete the resource group created in the first step. In this case, the following command deletes the resource group myTestResource.   

				
					az group delete --name myTestResource 
				
			

Docker is now running on Azure

Developers hardly have to look around for other services once they opt for Microsoft Azure. Not only can they configure their environments and Docker containers in it, but they can also run the containers and start developing their applications. Hence, companies are making cloud services like AWS and Azure fundamental parts of their technology stack.  With such value for money, no wonder enterprises are investing more into implementing cloud strategies.

Avatar for Emad Bin Abid
Emad Bin Abid

I'm a software engineer who has a bright vision and a strong interest in designing and engineering software solutions. I readily understand that in today's agile world the development process has to be rapid, reusable, and scalable; hence it is extremely important to develop solutions that are well-designed and embody a well-thought-of architecture as the baseline. Apart from designing and developing business solutions, I'm a content writer who loves to document technical learnings and experiences so that peers in the same industry can also benefit from them.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x