Last active
August 21, 2018 12:53
-
-
Save robv8r/e093a129b6d53f71c23d2421482d2fe8 to your computer and use it in GitHub Desktop.
Get all Docker Image with all Tags using Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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