Deploy your first Azure Container Instance.
1. Introduction
In this guide I’ll be guiding you on deploying an image to Azure Container Instance. To share a quick description of what ACI is, it’s a simple way for you to deploy a container image on Azure with out having to create an AKS cluster.
You can look into the previous guides if you haven’t already created custom images or for steps on how to pull an image from Docker Hub and push them to ACR.
2. Requirements
This will all be running on Azure so if you don’t have an account or subscription, you can set up a free trial here https://azure.microsoft.com/en-us/free/ which includes $200 limit for 30 days.
2.1 Installing Azure CLI
In this guide we will be using Azure CLI instead of Cloud Shell. The reason for this is that since we’ll be using Docker to create and push images to the Azure Container Registry it would be best that we have one single location to execute all the commands and steps to prevent confusion.
You can install Azure CLI on Windows, Linux, and Mac OS. Please follow the steps in the link below to install it on your PC. Once installed you can use any terminal available in your OS to run azure commands.
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli
2.2 Azure Login
After installing the Azure CLI, run the following command to Log in to your Azure Subscription. On Windows for example you can use Powershell or command prompt, on Linux/Mac OS you can use Terminal
|
|
This command will open an Internet Browser automatically and ask you to log in onto Azure with your credentials to authenticate.
Another option to login is to use the option ‘ –use-device-code ‘ which will allow you to authenticate from any device as this command will ask you to open a browser and go to ‘https://microsoft.com/devicelogin’ and enter a code to authenticate. You might also see this prompt without the device code option depending on where you are executing the ‘az login’ command, no need to worry, just follow the steps mentioned.
|
|
2.3 Installing Docker
Now let’s install Docker. This can be installed as well on Windows, Linux, and Mac OS by following the guide below: https://docs.docker.com/get-docker/
After installing and running docker, you can double check that docker is running by executing below command. If an error is displayed docker is not running and you might want to start it. This command is to list running containers, but since we have nothing currently running then no output will be displayed.
|
|
3. Check ACR and Image
Once you have your AZ CLI set up and Az Login ready from the previous steps let’s try to validate our registry’s full server address. In this guide I’ll be using the registry name myregistry4567, please replace this with your own registry name accordingly.
You can do this by running the command below:
|
|
Now let’s have a look at the repositories that we currently have available:
|
|
To list the tags for the repository that we want to use run below command:
|
|
Take note of the registry name, tag, and the complete registry server as we’ll need these for when we deploy the container instance later in this guide.
4. ACR Authentication
You can use multiple authentication methods to allow other services to be able to access and pull images from your Registry. In this guide I’ll be using the Admin credentials of the ACR for authentication, but additionally you can set up a service principal (sp) for authentication. For more details on using a service principal please head over to the link below for more information.
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-auth-aci
For production or large scale scenarios using a service principal is the best way to go as it’s more secure and you don’t have to share or integrate your admin passwords in your code/deployments.
If you currently don’t have the admin user enabled in your registry you can do so with below command:
|
|
To view the passwords for the admin user run below command;
|
|
5. Create a Resource Group
When you create and deploy your ACI, we will need to have an already created resource group and the region you want it to be created on. In the example below I’ll be using EastUS as the region and the resource group I’ve named it aci-rg, please feel free to change this accordingly.
|
|
6. Deploying your ACI
The command that we’ll be using to fully deploy the ACI is posted below, but let’s check all of the options that we’ll need to update.
- ‘–resource-group’ : This will be the name of the resource group we created.
- ‘–name’ : is the name of the Container Instance.
- ‘–image’ : is the complete image URL including the ACR address, name of the repository, and the tag version.
- ‘–cpu’ : is how many virtual cores you would like to assign the the Instance
- ‘–memory’ : would be how many GB of memory you would like to be available
- ‘–registry-login-server’ : is the complete server address for your registry.
- ‘–registry-username’ : is the ID of your Admin user or your SP
- ‘–registry-password’ : is the password for the Admin user or the SP
- ‘–ip-address’ : if you would like the IP to be public or private (if deploying in a specific vnet)
- ‘–dns-name-label’ : the FQDN that will connect you to the application.
- ‘–ports’ : the ports that will be used and will need to be opened by your application.
Run below to create your ACI. It will display /Running/ while it’s being created and when it’s complete you will get a large deployment output showing all of the ACI’s configurations.
|
|
You can view the status of your ACI by running below command:
|
|
You can also view the logs of the Container Instance by running below command:
|
|
7. Conclusion
You have successfully deployed and created your first Azure Container Instance. In this guide we deployed a Minecraft server image which we had created and later pushed to our Registry. If you would like to look at how this was done head over to https://ramirez.cr/aks-minecraft-server/ for more information.