Upload your image on Azure Container Registry

In my previous article, we went through the process of uploading our own image to Docker Hub. Even though it's perfectly fine to use Docker Hub, some organizations prefer using their own registries, either due to additional functionality that they might offer or due to policies and regulations. Since Azure offers a container registry resource that would fit most use cases, I thought we could try to upload some images and at least use it for test and dev purposes! 

First things first, the tools we're going to need. To upload an image to an ACR we need:

1. An Azure Container Registry
2. Docker Desktop
3. Azure CLI

Starting from the top of the list, we need the ACR resource to which we're going to upload the images. Clone my Github bicep repository and switch to the ContainerRegistry-ImageUpload-001/110-Bicep/110-AzureContainerRegistry/ folder. Update the parameters in the deploy script and submit the deployment. The output should be similar to the below:

If everything goes right, you should now have a new ACR, just like the one above!

The next step from here is to log in to the registry using docker. First, we need to get the credentials using the az acr credential show command. Make sure you're using the right name and resource group!

Now we need to build our images on our local system. Switch to the ContainerRegistry-ImageUpload-001/120-Dockerfiles/110-Web/ folder of the repository that contains the docker file for our web server and execute the docker build -t web . command. Docker will build an image named web using the docker file in the directory as context.

You can follow the same procedure for the database image located in the 120-Database folder (optional).

So, the images have been successfully built and are ready to be uploaded to the registry! To upload an image, we need to tag it and then push it, as shown below:

The command docker tag web [ACRLoginServer]/[imageName]:[imageVersion] tags the local image web according to the details of the registry, and the command docker push [ACRLoginServer]/[imageName]:[imageVersion] pushes it to the registry.

Make sure you're using the right values for the ACR and the names of the images. The names in the tag command should be the same used in the docker build command!

To verify the outcome of the process, you can get the images in your ACR using the az acr repository list command:

In this case, I've uploaded an image for the web server and an image for the database server. 

In the coming article, I'm going to use this approach to deploy a multi-container app on Azure AppService. Stay tuned!

Popular posts from this blog

Domain Controller Machine Password Reset

Configuring a Certificate on Exchange Receive Connector

Verbose Parameter Passing to cmdlet inside Function