Editar

Compartilhar via


Using Azure PowerShell in a Docker container

We publish Docker images with Azure PowerShell preinstalled. You can use Docker to run a standalone Linux container with Azure PowerShell preinstalled. This article shows you how to use Azure PowerShell in the Docker container.

Finding available images

The released images require Docker 17.05 or newer. You must be able to run Docker without sudo or local administrative rights. Follow Docker's official instructions to install Docker.

The release containers derive from the official distribution image, install dependencies, and install the Azure PowerShell module.

The latest container image contains the latest version of PowerShell and the latest Azure PowerShell modules supported with the Az PowerShell module.

You can find a complete list of Azure PowerShell Docker images on our Docker image page.

Using Azure PowerShell in a container

The following steps show the Docker commands required to download the image and start an interactive PowerShell session.

  1. Download the latest azure-powershell image.

    docker pull mcr.microsoft.com/azure-powershell:mariner-2
    
  2. Run the azure-powershell container in interactive mode:

    docker run -it mcr.microsoft.com/azure-powershell:mariner-2 pwsh
    

For Windows Docker hosts, you must enable Docker file sharing to allow local drives on Windows to be shared with Linux containers. For more information, see Get started with Docker for Windows.

Remove the image when no longer needed

The following command deletes the Docker container when you no longer need it.

docker rmi mcr.microsoft.com/azure-powershell:mariner-2

Next steps

To learn more about the Azure PowerShell modules and their features, see Get Started with Azure PowerShell.