Build your custom Azure CLI image

Build your custom Azure CLI image

As I've already mentioned, I love running Azure CLI from within a Docker container. There are various reasons why you'd want to do so, but the main ones are obviously isolation and seamless updates.

Microsoft maintains a constantly up-to-date image for Azure CLI in Docker Hub. We can easily run it with just one line of code, and Docker will download the image, create a container and attach the console to it.

docker run -it microsoft/azure-cli

However, one of the downsides is that every time we do it, we obtain a brand new container. This means that we'll have to re-authenticate, select the default subscription or even install your custom software - for example install and configure kubectl to control your Kubernetes AKS cluster in Azure.

This doesn't play well with Kitematic, for example, which allows us to easily expose ports or share volumes on existing containers, but ends up re-creating the container every time under the hoods.

The good news is that creating our personalised image, with our authentication details and custom software, is fairly simple. From within the container that we've created before, we can authenticate the client via az login:

This will require us to open a browser window and insert our credentials. In a similar way, we can go on and prepare the container that we require.

Once done, we can go back to the host machine and commit the container passing its id:

docker commit 561 marcodes/azure-cli -- your containerID might be different!

This will generate a new image, which already embeds our authentication details:

Awesome, job done! Just one recommendation: everyone who as access to that image, has access to your subscriptions! In other words, don't share it and never upload it to a public registry in Docker Hub!

Monikaben Lala

Founder | Product MVP Expert | Fiction Writer | Find me @Dubai Trade Show

8mo

Marco, thanks for sharing!

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore topics