CLI (선호) 또는 curl을 사용하여 원격 Docker 레지스트리에 Docker 이미지의 모든 태그를 나열하려면 어떻게해야합니까?
원격 레지스트리에서 모든 버전을 가져 오지 않는 것이 좋습니다. 태그 만 나열하고 싶습니다.
답변
나는 여기 에서 대답을 얻었다 . 고마워요! 🙂
한 줄짜리 스크립트 🙁 데비안의 모든 태그를 찾으십시오)
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 / 지방 / 빈에서 (또는 경로의 ENV를 추가 .bashrc
/ .zshrc
), 그 안에 그 코드를 넣어. 그런 다음 실행 권한 ( chmod +x dockertags
)을 추가하십시오 .
용법:
dockertags ubuntu
—> 우분투의 모든 태그를 나열
dockertags php apache
—> ‘apache’를 포함하는 모든 PHP 태그를 나열합니다.
답변
답변
docker registry v2 API를 사용하려면 페이지별로 태그를 나열합니다. 이미지의 모든 태그를 나열하려면 URL에 큰 page_size 매개 변수를 추가하십시오 (예 :
curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/centos/tags?page_size=1024'|jq '."results"[]["name"]'
답변
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 매개 변수를 파생시킵니다.
답변
curl을 사용하여 작동하도록했습니다.
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'
