CLI(推奨)またはcurlを使用して、リモートDockerレジストリー上のDockerイメージのすべてのタグを一覧表示するにはどうすればよいですか?
できれば、リモートレジストリからすべてのバージョンをプルしないでください。タグを一覧表示したいだけです。
docker(1)
github.com/docker/for-linux/issues/455
CLI(推奨)またはcurlを使用して、リモートDockerレジストリー上のDockerイメージのすべてのタグを一覧表示するにはどうすればよいですか?
できれば、リモートレジストリからすべてのバージョンをプルしないでください。タグを一覧表示したいだけです。
docker(1)
github.com/docker/for-linux/issues/455
回答:
たった1行のスクリプト:(debianのすべてのタグを見つける)
wget -q https://registry.hub.docker.com/v1/repositories/debian/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'
更新@degelfのアドバイスをありがとう。これがシェルスクリプトです。
#!/bin/bash
if [ $# -lt 1 ]
then
cat << HELP
dockertags -- list all tags for a Docker image on a remote registry.
EXAMPLE:
- list all tags for ubuntu:
dockertags ubuntu
- list all php tags containing apache:
dockertags php apache
HELP
fi
image="$1"
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`
if [ -n "$2" ]
then
tags=` echo "${tags}" | grep "$2" `
fi
echo "${tags}"
dockertags
/ usr / local / binの下に新しいファイル名を作成して(またはPATH envを.bashrc
/に追加して.zshrc
)、そのコードをそこに挿入するだけです。次に、実行可能権限(chmod +x dockertags
)を追加します。
使用法:
dockertags ubuntu
---> ubuntuのすべてのタグをリストします
dockertags php apache
--->「apache」を含むすべてのphpタグをリストしますphp
...
[backtick] でラップして、1行にまとめることができます。または、「debian」を$ 1に置き換え、/ usr / local / binの下の「dockertags」というスクリプトに入れます。次に、クロージングバックティックの前に、| grep $ 2を追加できます。次に、chmod + xで、「dockertags php apache」に移動して、apacheを含むすべてのphpタグを確認できます。
wget -q https://registry.hub.docker.com/v1/repositories/circleci/ruby/tags -O - | jq -r '.[].name'
jq
インストールした場合
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g'
はるかにきれいに書かれているtr -d '[]" '
userauth="-u ${2}"
を使用できるようにしました${userauth}
(空白の場合、uの切り替えやパラメーターは使用できません)。これは、プライベートリポジトリを使用するすべての
sed
は、クイックチェックに使用する方が実際にはよりシンプルに
docker registry v2 APIを使用する場合は、ページごとにタグがリストされます。画像のすべてのタグを一覧表示するには、大きなpage_sizeパラメータをURLに追加します。たとえば、
curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/centos/tags?page_size=1024'|jq '."results"[]["name"]'
https://registry.hub.docker.com/v2/repositories/library/centos/tags/?page=101
か?
java
画像は良い例です。はい、registry.hub.docker.com / v2 / repositories / library / java / tags /…のようなことができます。例については、結果のnext
およびprevious
リンクを参照してください。
Docker V2 APIには、適切なクレームを持つOAuthベアラートークンが必要です。私の意見では、公式文書はこのトピックについてはあいまいです。他の人が私と同じ苦痛を経験しないように、私は以下を提供しますdocker-tags
機能。
の最新バージョンはdocker-tags
私のGitHubGistにあります: "bashを使用してDockerイメージタグを一覧表示する"ます。
docker -tags関数はjqに依存しています。JSONで遊んでいる場合は、おそらくすでに持っているでしょう。
#!/usr/bin/env bash
docker-tags() {
arr=("$@")
for item in "${arr[@]}";
do
tokenUri="https://auth.docker.io/token"
data=("service=registry.docker.io" "scope=repository:$item:pull")
token="$(curl --silent --get --data-urlencode ${data[0]} --data-urlencode ${data[1]} $tokenUri | jq --raw-output '.token')"
listUri="https://registry-1.docker.io/v2/$item/tags/list"
authz="Authorization: Bearer $token"
result="$(curl --silent --get -H "Accept: application/json" -H "Authorization: Bearer $token" $listUri | jq --raw-output '.')"
echo $result
done
}
例
docker-tags "microsoft/nanoserver" "microsoft/dotnet" "library/mongo" "library/redis"
確かに、docker-tags
いくつかの仮定を行います。具体的には、OAuthリクエストパラメータはほとんどハードコードされています。より野心的な実装では、レジストリに認証されていない要求を行い、認証されていない応答からOAuthパラメータを導出します。
arr=("$@")
。ただ書くdocker-tags() { for item; do ....
私はそれをカールを使ってうまく動かすことができました:
curl -u <username>:<password> https://tutum.co/v1/repositories/<username>/<image_name>/tags
注image_name
名前付きイメージプッシュしている場合、例えば、ユーザ等の詳細情報を含むべきではないtutum.co/username/x
、その後はimage_name
する必要がありますx
。
Yan Fotoの回答(v2 api)に基づいて、特定の画像のタグをリストする単純なPythonスクリプトを作成しました。
使用法:
./docker-registry-list.py alpine
出力:
{
"name": "library/alpine",
"tags": [
"2.6",
"2.7",
"3.1",
"3.2",
"3.3",
"3.4",
"3.5",
"3.6",
"3.7",
"edge",
"latest"
]
}
JSON解析ツールの場合、jq
利用可能
wget -q https://registry.hub.docker.com/v1/repositories/debian/tags -O - | \
jq -r '.[].name'
'.[].name'
no matches found: .[].name
。しかし、それはbashでうまく機能します、おそらくそれはあなたのデフォルトのシェルですか?
jq
コマンドに引用符を追加しました
CLIユーティリティを参照してください:https : //www.npmjs.com/package/docker-browse
タグと画像の列挙を許可します。
docker-browse tags <image>
画像のすべてのタグが一覧表示されます。例えばdocker-browse tags library/alpine
docker-browse images
レジストリ内のすべての画像を一覧表示します。現在、で利用できませんindex.docker.io
。
Docker Registry HTTP API V2をサポートしている限り、プライベートレジストリを含む任意のレジストリに接続できます。
使用可能なすべてのタグをブラウザで表示するには:
https://registry.hub.docker.com/v1/repositories/<username>/<image_name>/tags
つまり、https://hub.docker.com/r/localstack/localstack/tags
または、このエンドポイントを使用してjson応答を取得できます。
https://registry.hub.docker.com/v1/repositories/localstack/localstack/tags
このスクラップを使用することもできます:
# vim /usr/sbin/docker-tags
&以下を追加(そのまま):
#!/bin/bash
im="$1"
[[ -z "$im" ]] && { echo -e '\e[31m[-]\e[39m Where is the image name ??' ; exit ; }
[[ -z "$(echo "$im"| grep -o '/')" ]] && { link="https://hub.docker.com/r/library/$im/tags/" ; } || { link="https://hub.docker.com/r/$im/tags/" ; }
resp="$(curl -sL "$link")"
err="$(echo "$resp" | grep -o 'Page Not Found')"
if [[ ! -z "$err" ]] ; then
echo -e "\e[31m[-]\e[39m No Image Found with name => [ \e[32m$im\e[39m ]"
exit
else
tags="$(echo "$resp"|sed -e 's|}|\n|g' -e 's|{|\n|g'|grep '"result"'|sed -e 's|,|\n|g'|cut -d '[' -f2|cut -d ']' -f1|sed '/"tags":/d'|sed -e 's|"||g')"
echo -e "\e[32m$tags\e[39m"
fi
実行可能にする:
# chmod 755 /usr/sbin/docker-tags
次に、最後に試してみます:
$ docker-tags testexampleidontexist
[-] No Image Found with name => [ testexampleidontexist ]
$ docker search ubuntu
$ docker-tags teamrock/ubuntu
latest
[ コマンドを実行する前に、$&#を知っておいてください]
Docker Hubからすべてのタグを取得する:このコマンドは、コマンドラインJSON
プロセッサjq
を使用JSON
して、Docker Hubレジストリから返されたタグ名を選択します(引用符はで削除されますtr
)。ライブラリをDocker Hubユーザー名に、debianをイメージ名に置き換えます。
curl -s 'https://registry.hub.docker.com/v2/repositories/library/debian/tags/' | jq -r '."results"[]["name"]'
これは私がWindows用に作成したPowershellスクリプトです。v1およびv2リポジトリを処理します。
Get-DockerImageVersions.ps1:
param (
[Parameter (Mandatory=$true)]$ImageName,
[Parameter (Mandatory=$false)]$RegistryURL
)
if (!$RegistryURL)
{
$RegistryURL = "https://registry.hub.docker.com/v1/repositories"
}
$list = ""
if ($RegistryURL -like "*v2*")
{
$list = "/list"
}
$URL = "$RegistryURL/$ImageName/tags$list"
write-debug $URL
$resp = Invoke-WebRequest -UseBasicParsing $URL | ConvertFrom-Json
if ($RegistryURL -like "*v2*")
{
$tags = $resp | select tags
$tags.tags
} else {
$tags = $resp | select name
$tags.name
}
これをターミナルで実行することで達成できます:
curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/mysql/tags/' | jq . | grep name
また、jqがない場合は、jqをインストールする必要があります。
sudo apt-get install jq
curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/mysql/tags/' | jq .results[].name
grepコマンドを保存します
curl -L -s 'https://registry.hub.docker.com/v1/repositories/danilobatistaqueiroz/job-wq-1/tags'
ユーザーが何らかの方法で間違ったタグを入力した場合に、レジスターに存在するrepo(Docker repo)に存在するすべてのタグのリストを提供する必要があるタスクを実装する必要がある場合、このことを行いました。だから私はバッチスクリプトでコードを持っています。
<html>
<pre style="background-color:#bcbbbb;">
@echo off
docker login --username=xxxx --password=xxxx
docker pull %1:%2
IF NOT %ERRORLEVEL%==0 (
echo "Specified Version is Not Found "
echo "Available Version for this image is :"
for /f %%i in (' curl -s -H "Content-Type:application/json" -X POST -d "{\"username\":\"user\",\"password\":\"password\"}" https://hub.docker.com/v2/users/login ^|jq -r .token ') do set TOKEN=%%i
curl -sH "Authorization: JWT %TOKEN%" "https://hub.docker.com/v2/repositories/%1/tags/" | jq .results[].name
)
</pre>
</html>
このため、次のようなバッチファイルに引数を指定できます。
Dockerfile Javaバージョン7
Docker Registry APIには、すべてのタグをリストするエンドポイントがあります。
Tutumにも同様のエンドポイントがあり、tutum-cliを介してアクセスする方法があるようですです。
tutum-cliを使用して、次のことを試してください。
tutum tag list <uuid>
powershell 5.1では、次のような単純なlist_docker_image_tags.ps1スクリプトがあります。
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$image
)
$url = "https://registry.hub.docker.com/v1/repositories/{0}/tags" -f $image
Invoke-WebRequest $url | ConvertFrom-Json | Write-Output
次に、このような4.7タグをgrepできます。
./list_docker_image_tags.ps1 microsoft/dotnet-framework | ?{ $_.name -match "4.7" }
すべてのタグをskopeoでリストできます。
அ ~ skopeo inspect docker://httpd |jq .RepoTags
[
"2-alpine",
"2.2-alpine",
"2.2.29",
"2.2.31-alpine",
"2.2.31",
"2.2.32-alpine",
"2.2.32",
"2.2.34-alpine",
"2.2.34",
"2.2",
"2.4-alpine",
"2.4.10",
"2.4.12",
"2.4.16",
"2.4.17",
"2.4.18",
"2.4.20",
"2.4.23-alpine",
"2.4.23",
"2.4.25-alpine",
"2.4.25",
"2.4.27-alpine",
"2.4.27",
"2.4.28-alpine",
"2.4.28",
"2.4.29-alpine",
"2.4.29",
"2.4.32-alpine",
"2.4.32",
"2.4.33-alpine",
"2.4.33",
"2.4.34-alpine",
"2.4.34",
"2.4.35-alpine",
"2.4.35",
"2.4.37-alpine",
"2.4.37",
"2.4.38-alpine",
"2.4.38",
"2.4.39-alpine",
"2.4.39",
"2.4.41-alpine",
"2.4.41",
"2.4.43-alpine",
"2.4.43",
"2.4",
"2",
"alpine",
"latest"
]
外部レジストリの場合:
அ ~ skopeo inspect --creds username:password docker://<registry-url>/<repo>/<image>
人々がRedHatレジストリからタグを読みたい場合https://registry.redhat.io/v2
、手順は次のとおりです。
# example nodejs-12 image
IMAGE_STREAM=nodejs-12
REDHAT_REGISTRY_API="https://registry.redhat.io/v2/rhel8/$IMAGE_STREAM"
# Get an oAuth token based on a service account username and password https://access.redhat.com/articles/3560571
TOKEN=$(curl --silent -u "$REGISTRY_USER":"$REGISTRY_PASSWORD" "https://sso.redhat.com/auth/realms/rhcc/protocol/redhat-docker-v2/auth?service=docker-registry&client_id=curl&scope=repository:rhel:pull" | jq --raw-output '.token')
# Grab the tags
wget -q --header="Accept: application/json" --header="Authorization: Bearer $TOKEN" -O - "$REDHAT_REGISTRY_API/tags/list" | jq -r '."tags"[]'
ローカルのOpenShiftレジストリにあるものと、上流のregistry.redhat.comにあるものを比較したい場合は、完全なスクリプトを次に示します。