Skip to content

Instantly share code, notes, and snippets.

@ravibhure
Forked from so0k/Query-Registry.ps1
Created January 24, 2017 04:00
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 ravibhure/7af10f839102327a13e1d1152830d10d to your computer and use it in GitHub Desktop.
Save ravibhure/7af10f839102327a13e1d1152830d10d to your computer and use it in GitHub Desktop.
Query a docker registry v2/_catalog endpoint from powershell
[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