Azure ACI docker 101

repos

learning-docker/2-azure-container-instance at main · spawnmarvel/learning-docker · GitHub

Exercise – Control restart behavior

use gitbash with az cli or login to a linux vm and install az cli, the run az login –tenant TENANT-ID

Or use putty or cloud shell



az container create --resource-group Rg-uk-learn-aci-001 --name mycontainer-restart-demo --image mcr.microsoft.com/azuredocs/aci-wordcount:latest --restart-policy OnFailure --location uksouth

Azure

Use cli or portal to check status, runs, logs and more.

logs

Exercise – Set environment variables

$COSMOS_DB_NAME specifies your unique database name. The command prints the endpoint address for your database. Here, the command saves this address to the Bash variable COSMOS_DB_ENDPOINT.

Run az cosmosdb keys list to get the Azure Cosmos DB connection key and store it in a Bash variable named COSMOS_DB_MASTERKEY:

Then we get the primary key from here

stored in bash.

Deploy a container that works with your database

The two environment variables you created in the last part, COSMOS_DB_ENDPOINT and COSMOS_DB_MASTERKEY, hold the values you need to connect to the Azure Cosmos DB instance.

Get the ip, In a browser, go to your container’s IP address.

Although these values don’t appear to your users through the voting application, it’s a good security practice to ensure that sensitive information (such as connection keys) isn’t stored in plain text.

Secure environment variables prevent clear text output. To use secure environment variables, use the --secure-environment-variables argument instead of the --environment-variables argument.

make a new new container with secure-envirnment-variables

Exercise – Use data volumes

Get key and mount it when making the container

az container create --resource-group Rg-uk-learn-aci-001 --name aci-demo-files --image mcr.microsoft.com/azuredocs/aci-hellofiles --location uksouth --ports 80 --ip-address Public --azure-file-volume-account-name $STORAGE_ACCOUNT_NAME --azure-file-volume-account-key $STORAGE_KEY --azure-file-volume-share-name aci-share-demo --azure-file-volume-mount-path /aci/logs/

Now visit ip

Submit text

Saved

cat it with linux or view it in portal

Exercise – Troubleshoot Azure Container Instances

Get the logs

Get events

Execute a command in your container

cat Dockerfile

Monitor CPU and memory usage on your container

In the Azure portal, Azure Container Instances CPU and memory usage information look like this: