How to Deploy and Run Containers Using Microsoft Azure Container Instances
Tags: azurecontainers, azurecontainerregistry, azureaci, azurecontainerinstances
Published: 2021-03-06 16:07:37

#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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tn77v1nf2gn60j156s0o.png)
*Image Credit: [AKFPartners] (https://akfpartners.com/growth-blog/vms-vs-containers)*

**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](https://dev.to/jonahandersson/virtualization-and-deploying-azure-virtual-machines-using-powershell-1l83), 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](https://docs.microsoft.com/en-us/azure/container-instances/container-instances-overview?WT.mc_id=AZ-MVP-5004251)

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

**Prerequisites** 
* Microsoft Azure Subscription 
* Resource Group 
* Azure CLI Command Tools
* VS Code 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x41z76a8ed5nxowj6l05.png)
Step #1: Login to your Azure Account using Azure CLI. Login via web browser and set subscription you want to use

```
az login
```

Step #2: Set the right and active Azure Subscription that you want to use 
```
az account set --subscription "<Name of Your Azure Subscription Account>"
```

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 mcr.microsoft.com/azuredocs/aci-helloworld \
    --ports 80
```
Step #4: Verify the creation of your container image creation by verifying on Azure Portal 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6846d0qqgjeqfgj7kbaf.PNG)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zx70qeydh96z9ysqthdd.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/waooezbw6bgvfx7xtw63.png)


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' 
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk0tk03j87mh268g1tbd.PNG)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agl4m9oocpzhvdo3m6y1.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ze9u4ycf87jo65yxtnr3.png)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26monrzlxgqjz1bsfvdj.png)

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">
```

#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] (https://docs.microsoft.com/en-us/azure/container-instances?WT.mc_id=AZ-MVP-5004251)

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](https://meetu.ps/c/4Lj8B/DLqv5/a). 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](https://twitter.com/cjkodare), connect via my [LinkedIn](https://linkedin.com/in/jonahandersson) and visit my [website](https://jonahandersson.tech/)