Azure Web Apps for Containers: List all docker images using PowerShell

Azure Web Apps for Containers lets you deploy containers to an Azure Web App. This way you get the best to two worlds: the flexibility and portability of containers combined with most of the great features of Azure App Services (authentication, scaling, SSL handling, backup, diagnostics, etc…).

Recently I needed to receive a list of all Web Apps for Containers and the full name of their attached docker images, and I will share my approach with you in this blog post:

Go to resources.azure.com

Go to resources.azure.com;In your browser go to resources.azure.com which will lead you to the Azure Resource Explorer website. You will be asked to login with your Azure AD credentials.In your browser go to https://resources.azure.com which will lead you to the Azure Resource Explorer website.
You will be asked to log in with your Azure AD credentials.

 

Select websites in your subscription

Select web sites in your subscription;The tree view to the left lets you navigate through the hierachy of resources. Follow the following 6 steps: 1. Click on the 'subscriptions' node 2. Click on your subscription. 3. Expand the 'providers' node 4. Select 'Microsoft.Web' (this is the provider that serves web apps) 5. Select 'stes' to get a list of all web app in JSON format. 6. Inside the JSON output you will find the attached docker images in the value starting with DOCKER|The tree view to the left lets you navigate through the hierarchy of resources.

Follow these six steps (shown above as green numbered circles):

  1. Click on the ‘subscriptions’ node
  2. Click on your subscription.
  3. Expand the ‘providers’ node
  4. Select ‘Microsoft.Web‘ (this is the provider that serves web apps)
  5. Select ‘sites’ to get a list of all web apps in JSON format.
  6. Inside the JSON output, you will find the attached docker images in the value starting with “DOCKER|

Get the PowerShell code

Get the PowerShell code;Click on the PowerShell tab. Then copy the PowerShell snippet below. This snippet will enable us to work with the raw output of the web apps in PowerShell.Click on the PowerShell tab.
Then copy the PowerShell snippet below.
This snippet will enable us to work with the raw output of the web apps in PowerShell.

Work with the web apps in PowerShell

Work with the web apps in PowerShell;Paste our snippet into PowerShell and assign it to a variable (in this case $sites)
Paste our snippet into PowerShell and assign it to a variable (in this case $sites)

Inspect the PowerShell objects

Inspect the PowerShell objects;We can use the 'Show-Objects' cmdlet to explorer how interprets the web apps data we got from Azure Resource Explorer.
We can use the ‘Show-Object’ cmdlet to explore how PowerShell interprets the web apps data we got from Azure Resource Explorer.

Show-Object inspection window

Show-Objects;With Show-Objects we can drill into the object structure, and just like we saw in the JSON input, we also have a 'value' here starting with 'DOCKER|' (step 1). Step 2 highlights the actual path into the object structure where our docker image resides.
With Show-Object we can drill into the object structure, and just like we saw in the JSON input, we also have a ‘value’ here starting with ‘DOCKER|‘ (step 1).

Step 2 highlights the actual path into the object structure where our docker image resides.

Receive the Docker images in PowerShell

Receive the Docker images in PowerShell;The following two steps will receive and display the docker images for our web apps: 1. pipe $sites into a where-object cmdlet (here using alias '?') appling the object path we found in Show-Object earlier. The we select the 'name' of the web app and the 'value' 2. The output then shows all docker images together with names of the web apps in which they run. Note: the 2nd docker image ('testcontainerreg002.azurecr.io/bitnami.bitnami/wordpress:4.9.6') is actual a docker images coming from a Azure Container registry that I use for testing purposes. The other two comes directly from Docker Hub (hub.docker.com)
The following two steps  will receive and display the docker images for our web apps:

  1. Pipe $sites into a Where-Object cmdlet (here using alias ‘?‘) appling the object path we found in Show-Object earlier. Then we select the ‘name’ of the web app and the ‘value’path
  2. The output then shows all docker images together with names of the web apps to which they are attached.

NOTE

The 2nd docker image (‘testcontainerreg002.azurecr.io/bitnami.bitnami/wordpress:4.9.6‘) is actual a docker image coming from a Azure Container Registry that I use for testing purposes. The other two comes directly from Docker Hub.

The full PowerShell code is here:

$sites = Get-AzureRmResource -ResourceId /subscriptions/2060338b-6824-47c3-b778-c86f1d58a534/providers/Microsoft.Web/sites -ApiVersion 2016-08-01
$sites[3] | Show-Object
$sites | ? {$_.Properties.siteProperties.properties.value -like "DOCKER|*" } | select name, {$_.Properties.siteProperties.properties.value}

Photo by maijou2501

2