| title | How to run Azure CLI in a Docker Container |
|---|---|
| description | Learn how to run the Azure CLI in a Docker container for a fast, isolated setup. Use Docker to simplify Azure CLI usage in any environment. |
| ms.service | azure-cli |
| ms.custom | devx-track-azurecli |
| keywords | azure cli docker, docker azure cli |
You can use Docker to run a standalone Linux container with Azure CLI preinstalled, providing a quick and isolated environment for using Azure CLI. This container image can also serve as a base for your own custom deployments.
Warning
Azure CLI 2.63.0 (released August 2024) is the final version supported on the Alpine-based Docker image. Microsoft no longer provides updates or bug fixes for this image. To ensure continued support, migrate to the Azure Linux-based image (Azure Linux 3.0), which is fully maintained. See the following examples for using Azure Linux 3.0.
To suppress warning messages, run: az config set core.only_show_errors=yes. For details on
configuration options, see Azure CLI configuration values and environment variables.
Follow Docker's official instructions to install Docker. The release containers derive from the official distribution image, install dependencies, and install Azure CLI.
You can find a complete list of Azure CLI Docker images on our Docker image page.
Important
These images are built from official operating system (OS) images provided by the OS distributor. These images might not have the latest security updates. Microsoft recommends that you update the OS packages to the latest version to ensure the latest security updates are applied.
Open a command prompt and start a Docker container with the Azure CLI preinstalled using the
following command. When using this command in a pipeline, use a deterministic tag (such as
azurelinux3.0) to ensure consistent behavior.
docker run -it mcr.microsoft.com/azure-cli:azurelinux3.0Note
To use your local SSH keys within the container, mount your .ssh directory by including the
following option: --mount type=bind,src="$HOME"/.ssh,dst=/root/.ssh. This option allows the
container to access your SSH keys from your user environment.
docker run -it --mount type=bind,src="$HOME"/.ssh,dst=/root/.ssh mcr.microsoft.com/azure-cli:azurelinux3.0The Azure CLI is available in the image as the az command, located at /usr/bin/az.
You can find available versions in the Azure CLI release notes.
To run a specific version of the Azure CLI in a Docker container, use the following command,
replacing 2.74.0 with your desired version.
docker run -it mcr.microsoft.com/azure-cli:2.74.0-azurelinux3.0To update the Azure CLI when using Docker, you must pull the latest image and recreate any existing containers. Because of this update process, avoid using Azure CLI containers as persistent data stores.
Update your local image using the following command:
docker pull mcr.microsoft.com/azure-cli:latest[!INCLUDE uninstall-boilerplate.md]
To remove the Docker image, first stop any running containers, then run:
docker rmi mcr.microsoft.com/azure-cliNow that you're ready to use the Azure CLI in a Docker container take a quick tour of its key features and commonly used commands to get started.
[!div class="nextstepaction"] Get started with the Azure CLI