Skip to content

Instantly share code, notes, and snippets.

@robv8r
Last active August 21, 2018 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robv8r/e093a129b6d53f71c23d2421482d2fe8 to your computer and use it in GitHub Desktop.
Save robv8r/e093a129b6d53f71c23d2421482d2fe8 to your computer and use it in GitHub Desktop.
Get all Docker Image with all Tags using Powershell
function Get-DockerImageTag {
[CmdletBinding()]
Param (
[Parameter()]
[string[]]
$ImageName
)
PROCESS {
Foreach($name in $ImageName) {
Write-Verbose("Image name: $name")
$authUri = "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$($name):pull"
Write-Verbose("Authorization Uri: $authUri")
$bearerToken = ( Invoke-RestMethod -Method Get -Uri $authUri | Select-Object -ExpandProperty token )
$listUri = "https://registry-1.docker.io/v2/$($name)/tags/list"
Write-Verbose $listUri
Invoke-RestMethod -Method Get -Uri $listUri -Headers @{ "Authorization" = "Bearer $bearerToken" }
}
}
}
<#
Example:
$imageNames = @( "microsoft/nanoserver","microsoft/dotnet", "library/redis", "library/mongo" )
Write-Host "Test #1 - Single Image - Prove one works"
Get-DockerImageTag -ImageName $imageNames[0] -Verbose
Write-Host "Test #2 - Two Images - Prove multiple works. Output may be buffered for short sequences."
Get-DockerImageTag -ImageName $imageNames[0],$imageNames[1] -Verbose
Write-Host "Test #3 - Many Images - Prove that the pipeline isn't buffered!"
Get-DockerImageTag -ImageName $imageNames -Verbose
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment