# Running the Azure CLI in a Container

DevFeed: [Running the Azure CLI in a Container](<https://devfeed.tech/articles/running-the-azure-cli-in-a-container-10923.md>)

Original publisher: [Read original article](<https://blog.scottlowe.org/2026/03/02/running-azure-cli-in-container/>)

Author: Scott Lowe

Published: 2026-03-02T13:00:00Z

Content type: tutorial

Language: en

Sources: [Scott's Weblog](<https://devfeed.tech/sources/scott-s-weblog.md>)

Topics: [Azure](<https://devfeed.tech/topics/azure.md>), [Docker](<https://devfeed.tech/topics/docker.md>), [Containers](<https://devfeed.tech/topics/containers.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Python](<https://devfeed.tech/topics/python.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [aws](<https://devfeed.tech/tags/aws.md>), [azure](<https://devfeed.tech/tags/azure.md>), [cilium](<https://devfeed.tech/tags/cilium.md>), [cli](<https://devfeed.tech/tags/cli.md>), [cloud](<https://devfeed.tech/tags/cloud.md>), [cni](<https://devfeed.tech/tags/cni.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [container](<https://devfeed.tech/tags/container.md>), [containers](<https://devfeed.tech/tags/containers.md>), [cri-o](<https://devfeed.tech/tags/cri-o.md>), [devops](<https://devfeed.tech/tags/devops.md>), [docker](<https://devfeed.tech/tags/docker.md>), [docker-container](<https://devfeed.tech/tags/docker-container.md>), [go](<https://devfeed.tech/tags/go.md>), [iac](<https://devfeed.tech/tags/iac.md>), [k8s](<https://devfeed.tech/tags/k8s.md>), [kubernetes](<https://devfeed.tech/tags/kubernetes.md>), [linux](<https://devfeed.tech/tags/linux.md>), [networking](<https://devfeed.tech/tags/networking.md>), [oci](<https://devfeed.tech/tags/oci.md>), [python](<https://devfeed.tech/tags/python.md>), [security](<https://devfeed.tech/tags/security.md>), [ssh](<https://devfeed.tech/tags/ssh.md>)

## AI overview

This article examines running the Azure CLI in a container. It finds that the standard Docker command works for an interactive shell, but using an alias from the current shell requires persisting Azure configuration and SSH keys. Running as root can also create files with root ownership, potentially requiring a custom image; the author therefore returns to using a Python virtual environment.

## Source excerpt

Like perhaps some readers, I am quite particular about what gets installed on my systems. I try to keep my systems as "clean" as possible, doing my best to avoid tools that have an extensive list of dependencies that must be installed and updated. Where that isn't possible--such as with the Azure CLI, which has a massive number of Python modules that are required in order for the tool to function--I will use various isolation mechanisms. For the Azure CLI, that's typically been a Python virtual environment. Somewhat recently, though, I had an idea to try using a container. In this post, I'll share what worked and what did not work when trying to run the Azure CLI in a container. First, though, a disclaimer: I am not an Azure expert, nor am I a Python expert. I know enough to get by. If I share something here that's incorrect, please contact me and constructively show me my errors so that I can fix them. Before I started down this path, I was sure this would be a slam dunk. I mean, this is what containers are for, right? If you do some web searches for running the Azure CLI in a container, you'll find articles that give you this command line: docker run -it mcr.microsoft.com/azure-cli (Note that this assumes you are using Docker instead of something like Podman.) This does work, as long as you're willing to operate in an interactive shell in the container. I was looking for something a bit different: I wanted to create an alias for az that executed the container in my current shell instead of putting me into a separate shell inside the container. Something like this, for example: alias az="docker container run --rm mcr.microsoft.com/azure-cli az" I quickly found that you need to map in your Azure configuration directory from outside the container, or your configuration won't persist. (In theory you could remove the --rm parameter and keep the container around.) Now the docker command in your alias starts to look like this: docker container run --rm -v ${HOME}/.azure:/r