title | description | author | ms.author | ms.date | ms.topic | ms.service | ms.custom | keywords |
---|---|---|---|---|---|---|---|---|
How to run Azure CLI in a Docker Container | Microsoft Docs |
Learn how to run a Docker container hosting the Azure CLI. Docker gets you started quickly with an isolated environment in which to run the Azure CLI. |
jiasli |
jiasli |
03/14/2024 |
concept-article |
azure-cli |
devx-track-azurecli |
azure cli docker, docker azure cli |
You can use Docker to run a standalone Linux container with the Azure CLI preinstalled. Docker gets you started quickly with an isolated environment to run the CLI in. The image can also be used as a base for your own deployments.
Warning
Azure CLI 2.63.0 (released in August 2024) is the last version supported on the Alpine docker image. Microsoft will not be providing additional updates or bug fixes for this image. Consider migrating to the Azure Linux-based image (cbl-mariner) for the Azure CLI, which is fully supported. See examples for cbl-mariner2.0
below.
To disable warning messages, run az config set core.only_show_errors=yes
. For more information on Azure CLI configuration settings, see CLI configuration values and environment variables.
Open a command prompt and start the Docker container with Azure CLI preinstalled using the following command. When used in a pipeline, it is recommended to use a deterministic tag name (for example cbl-mariner2.0
)
docker run -it mcr.microsoft.com/azure-cli:cbl-mariner2.0
Note
If you want to pick up the SSH keys from your user environment,
use -v ${HOME}/.ssh:/root/.ssh
to mount your SSH keys in the environment.
docker run -it -v ${HOME}/.ssh:/root/.ssh mcr.microsoft.com/azure-cli:cbl-mariner2.0
The CLI is installed on the image as the az
command in /usr/local/bin
.
Available versions can be found at Azure CLI release notes.
To run a specific version of the Azure CLI in the Docker container, use this command. Change 2.62.0
with your desired version.
docker run -it mcr.microsoft.com/azure-cli:2.62.0-cbl-mariner2.0
Updating with Docker requires both pulling the new image and re-creating any existing containers. For this reason, you should try to avoid using a container that hosts the CLI as a data store.
Update your local image with docker pull
.
docker pull mcr.microsoft.com/azure-cli:cbl-mariner2.0
[!INCLUDE uninstall-boilerplate.md]
After halting any containers running the CLI image, remove it.
docker rmi mcr.microsoft.com/azure-cli
Now that you're ready to use the Azure CLI in a Docker container, take a short tour of its features and common commands.
[!div class="nextstepaction"] Get started with the Azure CLI