Sign inSign up

lesca/az-pwsh

By lesca

Updated about 2 months ago

https://github.com/lesca/docker/tree/main/az-pwsh

Image
Developer tools
0

10K+

lesca/az-pwsh repository overview

This is an all-in-one docker image includes Azure PowerShell, Graph Powershell SDK, Azure CLI, Bicep CLI, .Net runtime, etc. The image is updated weekly to keep everything up-to-date.

The docker images are published in Docker Hub.

How to use the image?

You can simply pull the image by:

docker pull lesca/az-pwsh:latest

and run the image by:

docker run --rm -it lesca/az-pwsh:latest pwsh

Or, you can run the image in detach mode:

docker run -d --name azure lesca/az-pwsh:latest sleep infinity
docker exec -it azure pwsh

Also, you can mount a folder in detached mode:

docker run -d \
  --mount type=bind,source="$(pwd)/scripts",target=/root/scripts \
  --name azure lesca/az-pwsh:latest \
  sleep infinity
docker exec -it azure pwsh
Using with VS Code Dev Container

You can then connect to the running container from VS code -> Dev Containers: Attach to Running Container...

You can also simplify the process by adding a .devcontianer.json file in your project folder:

{
  "name": "az-pwsh",
  "image": "lesca/az-pwsh:dev",
  "workspaceFolder": "/root/azure",
  "workspaceMount": "source=${localWorkspaceFolder},target=/root/azure,type=bind,consistency=cached",
  "customizations": {
    "vscode": {
      "extensions": [
        "ms-vscode.powershell",
        "ms-vscode.azurecli",
        "ms-azuretools.vscode-bicep"
      ],
      "settings": {
        "http.proxy": "http://host.docker.internal:8080",
        "http.proxyStrictSSL": false
      }
    }
  }
}

Then, you can open the folder with Dev Containers: Open Folder in Container... command.

Why do I need this?

The image is based on Azure Powershell.

For windows, you can also use MSI package to install everything, however you need to manually maintain other moudles. Let's say the Graph moudles, the update is very time-wasting.

What does the image have?

Azure PowerShell

The workflow always uses official images from Microsoft. No 3rd party images are used.

You can find the images from the registry below:

The base image:

The tags used:

  • azurelinux-3.0 - for AMD64 CPU
  • azurelinux-3.0-arm64 - for ARM64 CPU
Azure CLI

This is installed by the tdnf the package mananger of AzureLinux 3.0 distribution.

You can also install it from Github - https://github.com/Azure/azure-cli/releases

Bicep CLI

This is installed by an installation script from Microsoft.

The installation source is from Github releases: https://github.com/Azure/bicep/releases

Resources:

PS Modules

The workflow always uses official PowerShell modules from Microsoft. No 3rd party modules are used.

To get a full list of installed modules, you can list the available modules by Get-InstalledModule and Get-Module -ListAvailable

Installed Modules
Deprecated Modules:

How to load PFX certs

You can use below script to load PFX certs in to My cert store:

function Import-PfxToCertStore {
    param (
        [string]$pfx,
        [string]$pass
    )
    # import the PFX to your machines cert store
    $StoreName = [System.Security.Cryptography.X509Certificates.StoreName]::My 
    $StoreLocation = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser 
    $Store = [System.Security.Cryptography.X509Certificates.X509Store]::new($StoreName, $StoreLocation) 
    $Flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable
    $Certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($pfx, $pass, $Flag) 
    $Store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) 
    $Store.Add($Certificate) 
    $Store.Close()
}

For AzCLI you need to convert pfx to pem before you can connect:

openssl pkcs12 -in $pfxPath --out $pemPath --nodes
az login --service-principal -u $clientId --certificate $pemPath --tenant $tenantId

Note: pem is not encrypted. Permenantly delete it after you finish your work.

How to upgrade PowerShell

In some cases, you may want to install a newer version of PowerShell. Since we are using AzureLinux 3.0, it's using rpm packages, we can refer to the installation guide from RHEL.

First, you can visit the Azure PowerShell release page and find the package link.

Then, use dnf install -y following the link, e.g:

dnf install -y https://github.com/PowerShell/PowerShell/releases/download/v7.5.3/powershell-7.5.3-1.cm.aarch64.rpm

Tag summary

Content type

Image

Digest

sha256:fd34685bc

Size

752.9 MB

Last updated

about 2 months ago

docker pull lesca/az-pwsh