Use Docker to run PowerShell in Azure Stack

In this article, you use Docker to create Windows-based containers on which to run the version of PowerShell that's required for working with the various interfaces. In Docker, you must use Windows-based containers.

Docker prerequisites

  1. Install Docker.

  2. In a command-line program, such as Powershell or Bash, enter:

        Docker --version
  3. You need to run Docker by using Windows containers that require Windows 10. When you run Docker, switch to Windows containers.

  4. Run Docker from a machine that's joined to the same domain as Azure Stack. If you are using the Azure Stack Development Kit (ASDK), you need to install the VPN on your remote machine.

Set up a service principal for using PowerShell

To use PowerShell to access resources in Azure Stack, you need a service principal in your Azure Active Directory (Azure AD) tenant. You delegate permissions with user role-based access control (RBAC).

  1. To set up your service principal, follow the instructions in Give applications access to Azure Stack resources by creating service principals.

  2. Note the application ID, the secret, and your tenant ID for later use.

Docker - Azure Stack API profiles module

The Dockerfile opens the Microsoft image microsoft/windowsservercore, which has Windows PowerShell 5.1 installed. The file then loads NuGet and the Azure Stack PowerShell modules, and downloads the tools from Azure Stack Tools.

  1. Download the azure-stack-powershell repository as a ZIP file, or clone the repository.

  2. Open the repository folder from your terminal.

  3. Open a command-line interface in your repository, and then enter the following command:

    docker build --tag azure-stack-powershell .
  4. When the image has been built, start an interactive container by entering:

        docker run -it azure-stack-powershell powershell
  5. The shell is ready for your cmdlets.

    Windows PowerShell
    Copyright (C) 2016 Microsoft Corporation. All rights reserved.
    PS C:\>
  6. Connect to your Azure Stack instance by using the service principal. You are now using a PowerShell prompt in Docker.

    $passwd = ConvertTo-SecureString <Secret> -AsPlainText -Force
    $pscredential = New-Object System.Management.Automation.PSCredential('<ApplicationID>', $passwd)
    Connect-AzureRmAccount -ServicePrincipal -Credential $pscredential -TenantId <TenantID>

    PowerShell returns your account object:

    Account    SubscriptionName    TenantId    Environment
    -------    ----------------    --------    -----------
    <AccountID>    <SubName>       <TenantID>  AzureCloud
  7. Test your connectivity by creating a resource group in Azure Stack.

    New-AzureRmResourceGroup -Name "MyResourceGroup" -Location "Local"

Next steps