The Azure Command Line Interface (CLI), tool is very useful for administrators that are looking to interact with the Azure platform beyond the Management Portal. The beauty of the Azure CLI is that the commands are the same across any platform. This means that you only have one set of commands to get familiar with and they can be used across Windows, Linux, Mac, etc.
One of the best things about the Azure CLI tool is that Microsoft publishes it as a Docker image, so you don’t even have to go through the pain of install it on your Linux box. With just a few simple commands you will have full access to Azure by running it in a container
In this blog post, I’ll get you going with docker and the Azure CLI for Ubuntu 16.04.01.
So, from an Ubuntu desktop the first thing we need to do is install Docker if you don’t already have it installed.
To Install Docker on your Ubuntu Linux Desktop, use this command. You may be promoted for the administrator password, and you will need to respond with ‘Y’ agreeing the disk space that will be used to install Docker.
sudo apt install docker.io
Once the installer completes without any errors run the following commend to check the installation:
Notice the message that says “Cannot connect to the Docker daemon. Is the docker daemon running on this host?”
This means that docker isn’t currently running. To start docker run the following command
sudo service docker start
Now to download the Azure CLI Docker images and run the container use the following command:
sudo docker run -it microsoft/azure-cli
Notice that the package needs to be downloaded the first time. Once the image is downloaded the container starts. You can tell that you are now in the container because the prompt changed to show root@<container-name>:/#.
At the new command prompt type, the following command:
The command runs successfully which allows you to now interact with Azure using the CLI running in a Docker Container!
Now the next step will be to authenticate to your Azure subscriptions. To do this run the following command:
The command will point you to the following page: https://aka.ms/devicelogin and to enter a code. When you get to the webpage you will type in the code that was provided in the terminal output:
Once you press continue you will need to enter the Sign in credentials for your Azure subscriptions.
Once you have successfully authenticated to Azure you will receive the following message on the Azure Sign in page.
Then after about 15 seconds the authentication will register with your container. The following output will appear in the terminal window.
Now that you are authenticated you can run commands using the Azure CLI. Below is the output of running the following command:
A great example is to see all of the VMs in your subscription run this command:
azure vm list
I hope this helps you to get started with the Azure CLI and enjoying using the tool as a Docker container!