Creating an Azure Container Registry

To create a new Azure Container Registry, we should start by creating a new resource group. Resource groups are a fundamental concept in Azure resource management: they allow us to group a collection of resources for management, deployment, and billing reasons. In general, all of the resources that have the same life cycle should be grouped into the same resource group. Let's get started:

  1. First, create a resource group by using the following command on the Azure CLI:
az group create --name handsOn --location westeurope

The preceding command creates a new resource group called handsOn in our account stored in the West Europe region.

  1. Next, we will create the Azure Container Registry by executing the following command:
az acr create --resource-group handsOn --name <container_registry_name> --sku Basic

The preceding command creates a new Azure Container Registry under the handsOn resource group with the name we have chosen. It also defines the Stock-Keeping Unit (SKU) for this resource—in our case, the basic one.

SKU usually refers to a specific variant of a product and all of the attributes that identify that type of product. In the same way, Microsoft Azure uses this term to identify a specific purchasable good or service. 

Now that we have created an Azure Container Registry, let's push the catalog_api image into the registry. To solve the other dependencies of our container, we will create another appsettings.json file dedicated to a Stage environment. Therefore, we will set the ASPNETCORE_ENVIRONMENT variable to Stage to apply the connection string needed by the container. We can proceed by creating the appsettings.Stage.json file in the following way:

{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"DataSource": {
"ConnectionString": "Server=catalog db.westeurope
.azurecontainer.io;Database=master;User=sa;
Password=P@ssw0rd"
},
"ESB": {
"ConnectionString": "host=catalog-esb.westeurope.
azurecontainer.io;username=guest;password=guest;"
,
"EndPointName": "ItemSoldOut"
},
"CacheSettings": {
"ConnectionString": "catalog-cache.westeurope.
azurecontainer.io:6379,abortConnect=false"
},
"AuthenticationSettings": {
"Secret": "<secret>",
"ExpirationDays" : "7"
}
}

The preceding appsettings.json file definition declares the endpoints for the catalog_db, catalog-esb, and catalog-cache containers. Every endpoint is composed of the name of the container we are going to create, followed by the syntax—<region_name>.azurecontainer.io. The first part represents the region, followed by the subdomain of the service we are using, in our case, azurecontainer.io. Let's continue by defining the steps to push our local image into the container registry previously created:

  1. Let's start by authenticating the Azure CLI in the container registry using the following command:
az acr login --name <container_registry_name>

This should return a Login Succeeded message to the CLI.

  1. After that, we can proceed by preparing the Docker image of our service and build the image by triggering the following command in the Catalog.API folder:
docker-compose build

This instruction creates a new Docker image based on the Dockerfile we already have in the project folder. The name of the image will depend on the name specified on the docker-compose.yml file and COMPOSE_PROJECT_NAME specified in the .env file: if the COMPOSE_PROJECT_NAME is store, then the command will create an image with the store_catalog_api name.

  1. It is possible to verify the resulting image by executing the docker images command:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
catalog_api latest 714e538b7da5 About a minute ago 618MB
  1. It is necessary to get the Azure Container Registry server address so that we can push the local image to the registry. We can proceed by tagging the container that we just created with the server address of the Azure Container Registry we created previously:
docker tag catalog_api <container_registry_name>.azurecr.io/catalog_api:v1
docker push <container_registry_name>.azurecr.io/catalog_api:v1

After tagging the image and using the docker push command, Docker will start uploading the container into our Azure container repository. Hence, we will be able to use our container image in all of the services provided by Azure. This upload usually takes some time, depending on the size of the image and the quality of your internet connection. When the upload is completed, it is possible to check the result by browsing the Container registries section of the Azure portal (https://portal.azure.com/):

In this case, we can see that we have created a container registry called handsonaspnetcoreacr under the handsOn resource group. Eventually, we can choose to create or manage the container registry directly from the portal. Now that we've pushed the container, we can proceed by configuring ACI.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.211.134