Prerequisites
- Use the Bash environment in Azure Cloud Shell.
- For installing azure cli on local refer following link to access the resoures using the azure-cli.
Step 1: Create a resource group
Container instances must be deployed into a resource group in a manner similar to other Azure resources. Resource groups can be used to manage and arrange related Azure resources.
az group create --name myResourceGroup --location eastus
Step 2: Create A Container
Using the Azure CLI command az container create, a container instance must be created in this stage. Using the Docker image “mcr.microsoft.com/azuredocs/aci-helloworld,” this command establishes a container with the name “mycontainer” in the designated Azure resource group (“myResourceGroup”). It also gives the container the DNS name label “aci-demo” and opens port 80 to network traffic.
az container create --resource-group myResourceGroup --name mycontainer
--image mcr.microsoft.com/azuredocs/aci-helloworld --dns-name-label aci-demo --ports 80
To obtain information about a particular container instance, use the az container display command. Here, it obtains details about the “mycontainer” container, which is housed in the “myResourceGroup” resource group. The Fully Qualified Domain Name (FQDN) and Provisioning State are properties that are exhibited in a table format using the –out table option. The attributes to display are specified by the –query argument.
az container show --resource-group myResourceGroup --name mycontainer
--query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table
Step 3: Pull The Container Logs
The command listed below can be used to get the logs for a particular container instance. Here, it obtains the logs from the “mycontainer” container, which is housed in the “myResourceGroup” resource group. When the containerized application is operating within the container instance, this command can be useful for monitoring and troubleshooting it.
az container logs --resource-group myResourceGroup --name mycontainer
Step 4: Attach output streams
Real-time communication with a container is possible by attaching its standard input, output, and error streams to the local terminal using the az container attach command. Here, it affixes to the “mycontainer” container inside the “myResourceGroup” resource group. The behavior of the containerized application operating within the container instance can be seen and debugged with the help of this command.
az container attach --resource-group myResourceGroup --name mycontainer
Step 5: Clean up resources
To remove a container instance, use the az container delete command. In this instance, it removes the “mycontainer” container instance from the resource group “myResourceGroup.” The container instance and its related resources are permanently removed from the Azure environment by using this command.
az container delete --resource-group myResourceGroup --name mycontainer
To list every container instance inside a given resource group, use the az container list command. Here, it outputs the data in a tabular manner and lists the container instances in the “myResourceGroup” resource group. An overview of the container instances deployed in the designated resource group is given by this command, together with pertinent details like IP address, name, image, and status.
az container list --resource-group myResourceGroup --output table
How To Deploy A Container To Azure Container Instances ?
In layman’s terms, how will it feel when a developer develops an app and a member of the testing team tries to test the application on his/her OS? They will have to install the packages, and libraries required to run the app. Well, in this case, the container makes it easy and faster to rapidly deploy and scale applications. The container provides an auto-scaling feature, when your containerized app gets more traffic, it scales up.