【Powershell】 命令行查看 docker远程可用 image 所有版本 tag

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 *

Refs:
docker-tags 命令行获取docker远程仓库上指定镜像的tag列表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值