How to create and set up Azure Container Instance to deploy your first Docker Image to Azure Using Azure CLI

Deploy Docker Image to ACI

When it comes to containers, Docker remains the most widely adopted open-source container in the container industry. Although there are other container solutions such as Artifactory Docker Registry, LXC (Linux), Hyper-V, and Windows Containers, rkt (works with Kubernetes), Podman (open-source container engine), runC (portability solution), and containerd (a container runtime). Each of these container solutions has its own set of approaches and use cases. This article discusses how to set up an Azure Container Instance and deploy a Docker image to it. With this in mind, it is also important that you also understand what an Azure Container Instance is all about. ACI, or Azure Container Instance, allows you to run your Docker image on Azure. To deploy a Docker image to Azure, first publish it to a container registry, then connect the container instance to the registry and deploy the image. You can review some related articles on Azure: How to Upload Batch Files to Azure Storage Account Using Azure CLI, Serverless in Azure: How to deploy a function app from Visual Studio to Azure Platform, How to build your first CI/CD Pipeline in Azure DevOps using ASP.Net Core Application and How to use container insights to get the full benefits of Azure Monitor for Azure Kubernetes workload

Docker images are published to a publicly accessible repository known as Docker Hub, a free docker registry that allows you to create one private repository and multiple public repositories. To begin, sign up for a Docker Hub account.

Docker Hub

Here we are going to see how to create Azure Container Instance using Azure CLI and pull an image from Docker Hub.

The prerequisites for getting along with me in this exercise is to have the following:

  1. Azure CLI is installed on your PC.
  2. Active Azure Subscription, if you don’t have one already sign up here.

Create a Resource Group

Next, create a resource group. A resource group is a logical folder that holds all your resources together. We are going to create one by running the below CLI command:

az group create --name <YourResourceGroupName> --location <ChoosePreferredLocation>
Creating a Resource Group

Create an Azure Container Instance (ACI)

We have created the resource group, it’s time to create the Container using the az container create command by providing the name of the resource group we have just created. Here we will use the public image  provided by Microsoft named This image packages a small web app written in Node.js that serves a static HTML page.

To create the container run:

az container create --resource-group My-Test-RG  --name my-con-aci --image --dns-name-label aci-con --ports 80
Deploying the container

We have successfully deployed the image to Azure Container Instance. Let’s check the status by running the below command:

az container show --resource-group <YourResourceGroupName> --name <YourContainerName --query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table
Checking the container deployment status

As you can see from the screenshot, the fully qualified domain name for the container is The FQDN is derived from the DNS name that we specified. While deploying the container, you might be prompted that the DNS name is now available. In this case, you have to choose a different DNS name that is available in your region.

Now, let’s browse to the URL using a web browser.

Azure Container Instance deployed successfully

Pull the container logs

When troubleshooting a container or the application it runs (or simply viewing its output), begin by viewing the container instance’s logs. Using the az container logs command, you can retrieve the container instance logs. To do so run the command below:

az container logs --resource-group <YourResourceName> --name <YourContainerName>
Pulling Container logs

The output shows the container’s logs, as well as the HTTP GET requests generated when you viewed the application in your browser.

Next, let’s attach output streams. You can connect your local standard out and standard error streams to the container’s standard out and standard error streams. This allows you to view its current output or interact with it as if the commands were running directly in your terminal.

To connect your local console to the container’s output streams, use the az container attach command as shown below:

az container attach --resource-group <YourResourceGroupName> --name <YourContainerName>
Note: This will continue to run without stopping. To stop it, press Ctrl + C key combination on your PC.  
Attaching output streams
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x