In this first post in my series about Azure containers, I will explain how you can create Azure container instances.
Latest posts by Baki Onur Okutucu (see all)

Containers comprise one of the techniques that enable us to virtualize operating systems (OSes). This technology simply allows applications and their dependencies to run in an isolated environment without having to provision a virtual machine first. Creating a container also creates all required infrastructure elements such as the OS and virtual networks in the background. This way, software developers only need to focus on deploying and running their software on a container image. Multiple containers can exist on the same machine sharing the same OS kernel.

Azure container instances ^

With Azure container instances, we can simply deploy containers in Azure container groups using container images. To consume container images, we need to create a new container image or use an existing image in an image repository. In our scenario, we are going to use existing Docker images available in the Docker repository. As a part of our PowerShell script, we will list all Docker container images and filter the results to find the one we need. Thus, we need to install Docker on our local machine to list the images first.

Listing container images using Docker ^

Once we've installed Docker, we can move on to finding the correct image we are looking for, using the following PowerShell commands to select the container image. I've specified "microsoft" as a keyword to narrow down the results, but you can certainly use whatever satisfies your needs.

$list = docker.exe search "microsoft"
$result = @()
$list | foreach{
$result += $_.split("  ")[0]
$result=$result.replace($result[0], "")
$image=$result | Out-GridView -PassThru -Title "Select a Container Image"
Listing available images in the Docker repository

Listing available images in the Docker repository

Creating an Azure container group ^

Before executing the following commands, please make sure your Azure PowerShell module version is 5.7.0 or higher.

It is now time to create an Azure container group specifying all required parameters as shown below.

In my scenario, I picked the image named "Microsoft/iis," an IIS web server installed on top of a Windows server. I will also be specifying the number of CPUs, the memory size in GB, the public IP address, and the required ports.


New-AzureRmResourceGroup -Name $ResourceGroup -Location $location

New-AzureRmContainerGroup `
-ResourceGroupName $ResourceGroup `
-Name $containername `
-OsType $OSType `
-DnsNameLabel $dnsNameLabel `
-Image $image `
-MemoryInGB 1 `
-Cpu 2 `
-IpAddressType Public `
-Port @(80,433,1433) `
-Tag latest
Creating a new Azure container group

Creating a new Azure container group

After creating the container instance, the state becomes Running. We can check its current status using the following command:

Get-AzureRmContainerGroup `
-ResourceGroupName $ResourceGroup `
-Name $containername
Getting the details of a container group

Getting the details of a container group

Getting the details of containers ^

After creating the container group, we can get the details of the container(s) in a container group using the command below:

Get-AzureRmContainerGroup `
-ResourceGroupName $ResourceGroup `
-Name $containername | `
select -ExpandProperty containers
Getting container details

Getting container details

With this command, we can see the details of the CPU, memory, port, and current state of the container. In our case there is only one container in the container group we've created. Using multiple containers in an Azure container group is currently restricted to Linux containers.

We can move one step forward to list all events during the provisioning in terms of pulling, creating, and starting the Docker image in Azure.

Get-AzureRmContainerGroup `
-ResourceGroupName $ResourceGroup `
-Name $containername | `
select -ExpandProperty containers | `
select -ExpandProperty events | `
Getting container events

Getting container events

Verifying access to containers ^

Now the container is running in an Azure container group, and we should now be able to access the web server in the container. The URL pattern for containers in Azure is

So we can navigate the website using a browser or the command below:

start "http://$dnsNameLabel.$"

Accessing the web server in a container

Accessing the web server in a container

Conclusion ^

Containerization is becoming more and more popular, as it allows us to create OSes in a few minutes without worrying about the rest. You can customize your applications, deploy them in containers in a fast and reliable way, and destroy them easily. Using Azure PowerShell along with Azure container instances makes it even better when you need to spin up multiple containers in minutes!

Subscribe to 4sysops newsletter!

In the next post, I will walk you through the steps to manage container images with the Azure Container Registry using PowerShell.

1 Comment
  1. A.Y. 1 month ago

    Nice post, thank you!

    I want to dynamically create an Azure Container Group with multiple instances.
    How to create an array of containers($containers) in Powershell syntax? I tried ArrayList, but with no luck:

    New-AzContainerGroup -Name $MyContainerGroup -ResourceGroupName $MyResourceGroup -Location $Location -Container $containers -ImageRegistryCredential $imageRegistryCredential -RestartPolicy Never


Leave a reply

Your email address will not be published.


© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account