-
-
Save 40a/908d4ab71f0cb8e7fdbb291fa8fbe2b8 to your computer and use it in GitHub Desktop.
Query a docker registry v2/_catalog endpoint from powershell
This file contains hidden or 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
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True,Position=1)] | |
$Filter=".*", | |
#TODO: handle https & no basic auth as well.. | |
$RegistryEndpoint = "registry.mysite.com", | |
$UserName = "user", | |
$Password = "password" | |
) | |
#encode credentials to Base64String | |
$AuthString = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($UserName):$($Password)")) | |
$Result = (Invoke-RestMethod -Uri "http://$RegistryEndpoint/v2/_catalog" -Method Get -Headers @{ Authorization = "Basic $AuthString";}).repositories -Match $Filter | |
Write-Host -ForegroundColor Green ("found {0} images:" -f $Result.count) | |
$Result | % { | |
$image=$_ | |
$image | |
(irm -uri "http://$RegistryEndpoint/v2/$image/tags/list" -Method Get -Headers @{ Authorization = "Basic $AuthString";}).tags | % { | |
$tag=$_ | |
" docker pull $RegistryEndpoint/${image}:${tag}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment