How to build and Run a container with ACR Tasks?

young business people working with digital tablet while discussing together in conference room
Table of contents
Reading Time: 3 minutes
Table of contents:
Introduction
Prerequisites
Start Cloud Shell
Create a Container Registry
Create a Docker File
Build and Push Image to Registry
Run the container
Conclusion

Introduction

ACR Tasks is a set of Azure CLI command features within Azure Container Registry. It provides cloud-based container image build facility for the platforms like Linux, Windows, and ARM, and can automate OS and framework patching for your docker containers. Further, this also helps to automate the build and push processing of your image to ACR based on the set of triggers.

Prerequisites

  • Azure Cloud Account
  • Cloud Shell
  • Storage Account

1. Firstly, start Cloud shell

  • Create Resource Group
  • Create a Storage account
  • Click on Cloud shell icon, select bash, click on show advance setting and create a file share by putting a name of your choice. If you already have created storage account, choose Region, Resource group and storage account as existing one.
cloudshell

2. Secondly, create a Container Registry

Create a new container registry, replacing <RESOURCE_GROUP_NAME> with the name you want to associate your registry in. For instance, I have a Resource Group buildtestRg1 in eastus region.

az acr create --resource-group buildtestRg1 \ 
--name acrbuildtestcn1 --sku Basic --admin-enabled true
create registry

Azure Container Registry is available in multiple service tiers, which is also known as SKUs. These tiers provide predictable pricing and several options for aligning the capacity and usage patterns of your private Docker registry in Azure. Likewise, i have put sku as basic, admin-enabled as true to allow access to repositories from other Azure services. Moreover, to verify, go to all services, click on container registries.

3. Further, Switch Directory to clouddrive located under the home directory. It’s a persistent storage created by Cloudshell.

cd $HOME/clouddrive

4. Create a Docker File

echo "FROM nginx" > Dockerfile

5. Build and push the image to Azure Container Registry using the created Docker file. Give this step some time in order to complete the process.

az acr build --image nginx:v1 --registry acrbuildtestcn1 \
--file Dockerfile .
docker build

Furthermore, It will create an image using the instructions specified in docker file and push it to the registry.

List Images in the registry

az acr repository list --name acrbuildtestcn1 --output table

Alternatively, in the Azure portal, refresh all resources to view the newly created container registry with the name nginx.

6. Lastly, Run the Container from the image pushed to registry.

az acr run --registry acrbuildtestcn1 --cmd '$Registry/nginx:v1' /dev/null
start container

Further, Given command will pull the docker image from the given registry and bring up a container. Adding to this, ACR tasks can also run multi-step tasks, using a YAML file to define steps to build, push, and optionally test multiple containers.

Conclusion:

That’s all. You’ve successfully created an Image and brought up a container. On the other hand, this eliminate any need of docker installation on our local system.

Happy Learning!!

References:

https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tasks-reference-yaml

https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tasks-overview

Written by 

Sunil is a technology enthusiast Devops Engineer with overall experience of 9 years. He possesses deep experience with CI/CD development, AWS and Google Cloud platforms, Kubernets,Docker and other Devops practices.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading