powershell
# Version Powershell 7
param(
$Image
)
$API="https://registry.hub.docker.com/v1/repositories"
function Usage {
Write-Host @"
Usage: docker-tags NAME[:TAG]
docker-tags list all tags for docker image on a remote registry.
Example:
docker-tags (default nginx)
docker-tags nginx
docker-tags nginx:1.15.8
docker search nginx | docker-tags
docker search nginx | docker-tags :1.15.8
echo nginx | docker-tags
echo nginx | docker-tags :1.15.8
"@
}
echo $Image
$ARG=$args[0]
if ($Image -eq $Null || $ARG -eq "-h") {
Usage
exit 0;
}
function GetTags(){
$image=$args[0]
# $tag=$2
$url="{0}/{1}/tags" -f $API,$image
echo "Request: $url"
$ret = (Invoke-WebRequest $url)
# Refs: https://www.debugger.wiki/article/html/1558616400666368
# $content = $ret.Content | ConvertTo-Json
# $content = $content | ConvertFrom-Json
$content = $ret.Content | ConvertFrom-Json
$content | ForEach-Object -Process { echo $_.name }
echo $tag
if ($tag -ne "" && $tag -ne $null) {
echo "test";
} else {
echo "test1";
}
}
GetTags $Image
Set alias:
临时设置:
Set-Alias docker-tags <.ps1 脚本的绝对路径>
永久设置:
# 使用vscode,打开 Microsoft.PowerShell_profile.ps1 文件
code $PRORILE
# 加下 Set-Alias
Set-Alias docker-tags -Value <.ps1 脚本的绝对路径>
查看 docker-tags:
Get-Alias docker-tags
# 或者
Get-Alias docker*
# 或者
Get-Alias -Definition <.ps1 脚本的绝对路径>
# 或者
Get-Alias docker-tags | Format-List *