Azure Container Instances
Azure Container Instances is a service hosted in Microsoft Azure, which offers the very simple way to run a docker container. With this service you do not have to provision any virtual machines. Your container will be deployed in the already existing set of VMs, hosted by Microsoft for this purpose only.
Assuming you already have pushed your docker image to Azure Container Registry (ACI), you are ready to run it. In this post, I will use image mywebapi, which I have created and pushed to ACI as desribed in this article.
This repository is whown at th enext picture:
To be clear, I want to run the container of shown image in Azure Container Instance service. This is called deployment.
To deploy the image you can use Azure Portal or Azure CLI toll az as shown in the next example. I recommend using of az tool, because it is easier to used it as repeating step than doing many clicks in the portal.
This is the command, which deploys the image to ACI service:
az container create --resource-group MYWEBAPI-RG --name mywebapi --image damir.azurecr.io/mywebapi:latest --cpu 1 --memory 1 --registry-password <acrPassword> --ip-address public --ports 80
Please note green-marked values in the image and arguments of the az command.
Password can be found in the Azure Portal under Access Keys of the registry. Argument CPU specifies the number of required CPUs and MEMORY specifies RAM in GB.
Deployemt is extremely fast operation. Just few seconds after executing command, container is online.
As a result you will get following:
{
"containers": [
{
"command": null,
"environmentVariables": [],
"image": "damir.azurecr.io/mywebapi:latest",
"instanceView": null,
"name": "mywebapi",
"ports": [
{
"port": 80,
"protocol": null
}
],
"resources": {
"limits": null,
"requests": {
"cpu": 1.0,
"memoryInGb": 1.0
}
},
"volumeMounts": null
}
],
"id": "/subscriptions/???/resourceGroups/MYWEBAPI-RG/providers/Microsoft.ContainerInstance/containerGroups/mywebapi",
"imageRegistryCredentials": [
{
"password": null,
"server": "damir.azurecr.io",
"username": "damir"
}
],
"instanceView": {
"events": [],
"state": "Pending"
},
"ipAddress": {
"ip": "52.166.167.192",
"ports": [
{
"port": 80,
"protocol": "TCP"
}
]
},
"location": "westeurope",
"name": "mywebapi",
"osType": "Linux",
"provisioningState": "Creating",
"resourceGroup": "MYWEBAPI-RG",
"restartPolicy": "Always",
"tags": null,
"type": "Microsoft.ContainerInstance/containerGroups",
"volumes": null
}
JSON shown above is a summory of created resource. One of intersting values is public IP address, which right now cannt be the static one.
You can now access your web api with following URL:
http://52.166.167.192/api/values/3
You can also get IP address by using of following command:
az container show --resource-group MYWEBAPI-RG --name mywebapi --query ipAddress.ip
After deployent, in the portal you will see something like this:
If you want to take a look on the application log, use following command:
az container logs --resource-group MYWEBAPI-RG --name mywebapi
This will give you following result:
[40m[1m[33mwarn[39m[22m[49m: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {8274b2e3-60ce-4ee0-a0bc-effeb14b6f51} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.