DEV Community

Cover image for How to Deploy and Run Containers Using Microsoft Azure Container Instances
Jonah Andersson 👩🏻‍💻
Jonah Andersson 👩🏻‍💻

Posted on • Updated on

How to Deploy and Run Containers Using Microsoft Azure Container Instances

What is a Container and What is it with Containers on the Cloud?

Container technology was initially from the Linux world.
Lately, containers are nowadays commonly used in Windows environments. One of the widely used implementations of container technology is the use of Docker containers.

The word Container actually describes itself. It is like a container box with all your stuff in it.

In software development and in cloud development, containerizing applications have been trending these days, especially as an alternative to using Virtual Machines as Infrastructure as a Service (IaaS).

Alt Text
Image Credit: AKFPartners

If we talk about software engineering, what is a container then?

A container is a piece of software that packages your application, all your source code, and all its dependencies in a single box or package. Just like when you pack up everything you need to move to a new house or another location. So, this box, package or known as "container" can be run and executed directly by any computer systems or environment - for example on environments Linux or Microsoft Windows.

How does containers work? Why is it better than using Virtual Machines?

Practical questions like these are worth asking for. Using Virtual Machines or Containers depend on what kind of business requirements or technical problems you want to solve. Just like anything, there are pros and cons. Virtualization and container technologies are both great! It is really up to what is it that needs to be built!

Containers vs. Virtual Machines

Unlike Virtual Machines, Containers run differently. When you execute a container, it only uses that read-only copy of the operating system's shared libraries that your application source code needs to run. Because of this, the required amount of resources are reduced and are lesser compared to running your applications on a virtual machine. Which means that containers give the benefits of portability, flexibility if you want to consider multi-cloud or multi-platform, it is also lightweight and platform independent.

Microsoft Azure Container Instances - Containers on the Cloud!

There are many container providers to choose from these days. If you have your applications running in Azure, then there are some cloud container services available for its users.

The following are some of the Azure Services for container development:

  • Azure Kubernetes Services (AKS)
  • Azure Service Fabric
  • Azure Web Apps for Containers
  • Azure Container Registry
  • Azure Container Instances

On this article, I will go through briefly Azure Container Instances and show a simple example on how to deploy a docker container image using Azure Portal and Azure CLI.

Azure Container Instances

Azure Container Instances offers the fastest and simplest way to run a container in Azure, without having to manage any virtual machines and without having to adopt a higher-level service.
Azure Container Instances is a great solution for any scenario that can operate in isolated containers, including simple applications, task automation, and build jobs. For scenarios where you need full container orchestration, including service discovery across multiple containers, automatic scaling, and coordinated application upgrades, we recommend Azure Kubernetes Service (AKS).
-Source Credit: Microsoft Documentation

How to Deploy and Run Container Image to Azure Container Instances using Azure Portal and Azure CLI


  • Microsoft Azure Subscription
  • Resource Group
  • Azure CLI Command Tools
  • VS Code

Alt Text
Step #1: Login to your Azure Account using Azure CLI. Login via web browser and set subscription you want to use

az login
Enter fullscreen mode Exit fullscreen mode

Step #2: Set the right and active Azure Subscription that you want to use

az account set --subscription "<Name of Your Azure Subscription Account>"
Enter fullscreen mode Exit fullscreen mode

Step #3: Deploy a container image from a public registry. Below example, Hello world ACI

az container create \
    --resource-group <name-of-your-resource-group>\
    --name psdemo-hello-world-cli \
    --dns-name-label psdemo-hello-world-cli \
    --image \
    --ports 80
Enter fullscreen mode Exit fullscreen mode

Step #4: Verify the creation of your container image creation by verifying on Azure Portal

Alt Text

Click on the Azure Container Instance that was created using the Azure CLI command you just executed then you will find that the container image is in it.

Alt Text

Alt Text

Step #5: Go back to your VS Code and using Azure CLI command below to check your container information

az container show --resource-group '<name-of-your-resource-group>' --name 'psdemo-hello-world-cli' 
Enter fullscreen mode Exit fullscreen mode

Alt Text

Step #6: You can also verify if your container image is publicly active and exposed to port 80 by using the URL on FQDN address on the Azure Container Instance on Azure Portal. You can either use the Public IP address or the URL.

Alt Text

Alt Text

Browse to the public IP-address and you will see a running Azure Container Instance.

Alt Text

Step # 7: Finally, clean up if you are just testing and trying out or continue with your development! :)

To clean up, delete the entire resource group for your hands-on and delete the local docker container images on your machine

az group delete --name <"Name of Your Resource Group"> --yes
docker image rm <"Name of Docker Image for Container Instance To Remove">
docker image rm <"Name of Docker Image To Remove">
Enter fullscreen mode Exit fullscreen mode

Getting Started Guide and Learning Resources

To learn more about Azure Container Instances and how to continue developing containers with it, Azure Container Registry and Azure Kubernetes, check out Microsoft's Documentation for Azure Container Instances

I hope you learned something and interested to learn more.
If you like this article, please re-share the knowledge!

Feel free to leave feedback and ask questions.

About Author:
Jonah Andersson is a Filipina-Swedish Software Developer who codes full stack system development in C# .NET/NET Core. She is a Microsoft MVP for Azure, MCT, and founder/organizer of Azure User Group Sundsvall Sweden. She currently works as a Software Developer Consultant at Forefront Consulting in Sweden. Jonah is passionate about continuous learning, developing and sharing knowledge about Microsoft Azure cloud technologies. She one of the #AzureHeroes in Sweden. A woman who codes in tech who enjoys writing, advocating gender equality in the tech industry through mentorship and by being role model on her spare time.

Follow me Twitter, connect via my LinkedIn and visit my website

Top comments (0)