Skip to content

Latest commit

 

History

History
78 lines (54 loc) · 2.83 KB

run-azure-cli-docker.md

File metadata and controls

78 lines (54 loc) · 2.83 KB
title description author ms.author ms.date ms.topic ms.service ms.tool 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
conceptual
azure-cli
azure-cli
devx-track-azurecli, seo-azure-cli
azure cli docker, docker azure cli

How to run the Azure CLI in a Docker container

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.

With the release of Azure CLI version 2.54.0, the size of the Docker image of azure-cli is reduced from 1.1 GB to 700 MB! This reduction is a 36.3% decrease resulting in improved download speed and faster startup.

Start the Docker container with Azure CLI preinstalled

Note

The Azure CLI has migrated to Microsoft Container Registry. Existing tags on Docker Hub are still supported, but new releases will only be available as mcr.microsoft.com/azure-cli.

Open a command prompt and then start the Docker container with Azure CLI preinstalled using the following command.

docker run -it mcr.microsoft.com/azure-cli

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

The CLI is installed on the image as the az command in /usr/local/bin.

Run the Docker container with a specific version of the Azure CLI

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:

docker run -it mcr.microsoft.com/azure-cli:<version>

Update Docker image

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

Uninstall Docker image

[!INCLUDE uninstall-boilerplate.md]

After halting any containers running the CLI image, remove it.

docker rmi mcr.microsoft.com/azure-cli

Next Steps

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