Docker 명령 줄의 Docker 레지스트리에서 특정 태그가있는 Docker 이미지를 찾으려면 어떻게해야합니까?
Docker 이미지에 대한 특정 태그를 찾으려고합니다. 명령 줄에서 어떻게 할 수 있습니까? 모든 다운로드를 피하고 불필요한 이미지를 제거하려고합니다.
공식 우분투 릴리스 https://registry.hub.docker.com/_/ubuntu/ 에는 몇 가지 태그 (릴리스)가 있지만 명령 줄에서 검색하면
user@ubuntu:~$ docker search ubuntu | grep ^ubuntu
ubuntu Official Ubuntu base image 354
ubuntu-upstart Upstart is an event-based replacement for ... 7
ubuntufan/ping 0
ubuntu-debootstrap 0
또한 명령 줄 search
https://docs.docker.com/engine/reference/commandline/search/ 의 도움말에서 작동 방법에 대한 단서가 없습니까?
docker search
명령 에서 가능 합니까?
원시 명령을 사용하여 Docker 레지스트리 API 를 통해 검색 하면 정보를 가져올 수 있습니다.
$ curl https://registry.hub.docker.com//v1/repositories/ubuntu/tags | python -mjson.tool
[
{
"layer": "ef83896b",
"name": "latest"
},
.....
{
"layer": "463ff6be",
"name": "raring"
},
{
"layer": "195eb90b",
"name": "saucy"
},
{
"layer": "ef83896b",
"name": "trusty"
}
]
내가 아는 한 CLI는 저장소에서 태그 검색 / 나열을 허용하지 않습니다.
하지만 원하는 태그를 알고 있다면 콜론과 이미지 이름을 추가하여 명시 적으로 가져올 수 있습니다. docker pull ubuntu:saucy
CoreOS jq
를 사용하면 JSON 데이터를 구문 분석 할 수 있습니다.
이전에했던 것처럼 library/centos
$ curl -s -S 'https://registry.hub.docker.com/v2/repositories/library/centos/tags/' | jq '."results"[]["name"]' |sort
"6"
"6.7"
"centos5"
"centos5.11"
"centos6"
"centos6.6"
"centos6.7"
"centos7.0.1406"
"centos7.1.1503"
"latest"
이제 더 깨끗한 v2 API를 사용할 수 있으며 이것이 제가 예제에서 사용하고있는 것입니다. 간단한 스크립트를 작성하겠습니다 docker_remote_tags
.
#!/usr/bin/bash
curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$@/tags/" | jq '."results"[]["name"]' |sort
다음을 활성화합니다.
$ ./docker_remote_tags library/centos
"6"
"6.7"
"centos5"
"centos5.11"
"centos6"
"centos6.6"
"centos6.7"
"centos7.0.1406"
"centos7.1.1503"
"latest"
참고:
jq
: https://stedolan.github.io/jq/ |apt-get install jq
A) 내가 가지고 있지 않고 설치하고 싶지 않은 외부 라이브러리가 필요했기 때문에 위의 솔루션이 마음에 들지 않았습니다. B) 모든 페이지를 얻지 못했습니다.
Docker API는 요청 당 항목을 100 개로 제한합니다. 이것은 각 "다음"항목을 반복하여 모두 가져옵니다 (Python의 경우 7 페이지, 다른 항목은 다소 다를 수 있습니다.).
정말로 스팸을 보내고 싶다면 | cut -d '-' -f 1
마지막 줄에서 제거 하면 모든 것을 볼 수 있습니다.
url=https://registry.hub.docker.com/v2/repositories/library/redis/tags/?page_size=100 `# Initial url` ; \
( \
while [ ! -z $url ]; do `# Keep looping until the variable url is empty` \
>&2 echo -n "." `# Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)` ; \
content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))') `# Curl the URL and pipe the output to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages) then continue to loop over the results extracting only the name; all will be stored in a variable called content` ; \
url=$(echo "$content" | head -n 1) `# Let's get the first line of content which contains the next URL for the loop to continue` ; \
echo "$content" | tail -n +2 `# Print the content without the first line (yes +2 is counter intuitive)` ; \
done; \
>&2 echo `# Finally break the line of dots` ; \
) | cut -d '-' -f 1 | sort --version-sort | uniq;
샘플 출력 :
$ url=https://registry.hub.docker.com/v2/repositories/library/redis/tags/?page_size=100 `#initial url` ; \
> ( \
> while [ ! -z $url ]; do `#Keep looping until the variable url is empty` \
> >&2 echo -n "." `#Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)` ; \
> content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))') `# Curl the URL and pipe the JSON to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages) then continue to loop over the results extracting only the name; all will be store in a variable called content` ; \
> url=$(echo "$content" | head -n 1) `#Let's get the first line of content which contains the next URL for the loop to continue` ; \
> echo "$content" | tail -n +2 `#Print the content with out the first line (yes +2 is counter intuitive)` ; \
> done; \
> >&2 echo `#Finally break the line of dots` ; \
> ) | cut -d '-' -f 1 | sort --version-sort | uniq;
...
2
2.6
2.6.17
2.8
2.8.6
2.8.7
2.8.8
2.8.9
2.8.10
2.8.11
2.8.12
2.8.13
2.8.14
2.8.15
2.8.16
2.8.17
2.8.18
2.8.19
2.8.20
2.8.21
2.8.22
2.8.23
3
3.0
3.0.0
3.0.1
3.0.2
3.0.3
3.0.4
3.0.5
3.0.6
3.0.7
3.0.504
3.2
3.2.0
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.2.6
3.2.7
3.2.8
3.2.9
3.2.10
3.2.11
3.2.100
4
4.0
4.0.0
4.0.1
4.0.2
4.0.4
4.0.5
4.0.6
4.0.7
4.0.8
32bit
alpine
latest
nanoserver
windowsservercore
bash_profile
버전 을 원하는 경우 :
function docker-tags () {
name=$1
# Initial URL
url=https://registry.hub.docker.com/v2/repositories/library/$name/tags/?page_size=100
(
# Keep looping until the variable URL is empty
while [ ! -z $url ]; do
# Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)
>&2 echo -n "."
# Curl the URL and pipe the output to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages)
# then continue to loop over the results extracting only the name; all will be stored in a variable called content
content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))')
# Let's get the first line of content which contains the next URL for the loop to continue
url=$(echo "$content" | head -n 1)
# Print the content without the first line (yes +2 is counter intuitive)
echo "$content" | tail -n +2
done;
# Finally break the line of dots
>&2 echo
) | cut -d '-' -f 1 | sort --version-sort | uniq;
}
그리고 간단히 호출하십시오. docker-tags redis
샘플 출력 :
$ docker-tags redis
...
2
2.6
2.6.17
2.8
--trunc----
32bit
alpine
latest
nanoserver
windowsservercore
이 스크립트 (docker-show-repo-tags.sh)는 curl, sed, grep 및 sort가있는 Docker 지원 호스트에서 작동해야합니다. 이것은 저장소 태그 URL이 변경되었다는 사실을 반영하기 위해 업데이트되었습니다.
#!/bin/sh
#
# Simple script that will display Docker repository tags
# using basic tools: curl, sed, grep, and sort.
#
# Usage:
# $ docker-show-repo-tags.sh ubuntu centos
for Repo in $* ; do
curl -sS "https://hub.docker.com/r/library/$Repo/tags/" | \
sed -e $'s/"tags":/\\\n"tags":/g' -e $'s/\]/\\\n\]/g' | \
grep '^"tags"' | \
grep '"library"' | \
sed -e $'s/,/,\\\n/g' -e 's/,//g' -e 's/"//g' | \
grep -v 'library:' | \
sort -fu | \
sed -e "s/^/${Repo}:/"
done
이 이전 버전은 더 이상 작동하지 않습니다.
#!/bin/sh
# WARNING: This no long works!
# Simple script that will display Docker repository tags.
#
# Usage:
# $ docker-show-repo-tags.sh ubuntu centos
for Repo in $* ; do
curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$Repo/tags/" | \
sed -e $'s/,/,\\\n/g' -e $'s/\[/\\\[\n/g' | \
grep '"name"' | \
awk -F\" '{print $4;}' | \
sort -fu | \
sed -e "s/^/${Repo}:/"
done
다음은 간단한 예의 출력입니다.
$ docker-show-repo-tags.sh centos | cat -n
1 centos:5
2 centos:5.11
3 centos:6
4 centos:6.10
5 centos:6.6
6 centos:6.7
7 centos:6.8
8 centos:6.9
9 centos:7.0.1406
10 centos:7.1.1503
11 centos:7.2.1511
12 centos:7.3.1611
13 centos:7.4.1708
14 centos:7.5.1804
15 centos:centos5
16 centos:centos5.11
17 centos:centos6
18 centos:centos6.10
19 centos:centos6.6
20 centos:centos6.7
21 centos:centos6.8
22 centos:centos6.9
23 centos:centos7
24 centos:centos7.0.1406
25 centos:centos7.1.1503
26 centos:centos7.2.1511
27 centos:centos7.3.1611
28 centos:centos7.4.1708
29 centos:centos7.5.1804
30 centos:latest
필자는 PyTools GitHub repo 에서 사용 가능한 DockerHub repo 태그 검색을 단순화하는 명령 줄 도구를 작성했습니다 . 다양한 명령 줄 스위치와 함께 사용하는 것은 간단하지만 기본적으로는 다음과 같습니다.
./dockerhub_show_tags.py repo1 repo2
도커 이미지로도 사용할 수 있으며 여러 저장소를 사용할 수 있습니다.
docker run harisekhon/pytools dockerhub_show_tags.py centos ubuntu
DockerHub
repo: centos
tags: 5.11
6.6
6.7
7.0.1406
7.1.1503
centos5.11
centos6.6
centos6.7
centos7.0.1406
centos7.1.1503
repo: ubuntu
tags: latest
14.04
15.10
16.04
trusty
trusty-20160503.1
wily
wily-20160503
xenial
xenial-20160503
스크립트에 포함하려면 -q / --quiet을 사용하여 일반 도커 명령과 같이 태그 만 가져옵니다.
./dockerhub_show_tags.py centos -q
5.11
6.6
6.7
7.0.1406
7.1.1503
centos5.11
centos6.6
centos6.7
centos7.0.1406
centos7.1.1503
The v2 API seems to use some kind of pagination, so that it does not return all the available tags. This is clearly visible in projects such as python
(or library/python
). Even after quickly reading the documentation, I could not manage to work with the API correctly (maybe it is the wrong documentation).
Then I rewrote the script using the v1 API, and still using jq
:
#!/bin/bash
repo="$1"
if [[ "${repo}" != */* ]]; then
repo="library/${repo}"
fi
url="https://registry.hub.docker.com/v1/repositories/${repo}/tags"
curl -s -S "${url}" | jq '.[]["name"]' | sed 's/^"\(.*\)"$/\1/' | sort
The full script is available at: https://bitbucket.org/denilsonsa/small_scripts/src/default/docker_remote_tags.sh
I've also written (in Python) an improved version that aggregates tags that point to the same version: https://bitbucket.org/denilsonsa/small_scripts/src/default/docker_remote_tags.py
Add this function to your .zshrc file or run the command mannually
#usage list-dh-tags <repo>
#example: list-dh-tags node
function list-dh-tags(){
wget -q https://registry.hub.docker.com/v1/repositories/$1/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'
}
thanks to this -> How to list all tags for a Docker image on a remote registry?
Reimplementation of the previous post, using Python over sed/awk:
for Repo in $* ; do
tags=$(curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$Repo/tags/")
python - <<EOF
import json
tags = [t['name'] for t in json.loads('''$tags''')['results']]
tags.sort()
for tag in tags:
print "{}:{}".format('$Repo', tag)
EOF
done
For a script that works with Oauth bearer tokens on Docker hub, try this:
Listing the tags of a Docker image on a Docker hub through the HTTP API
You can use Visual Studio Code to provide autocomplete for available docker images and tags. However, this requires that you type the first letter of a tag in order to see autocomplete suggestions.
For example when writing FROM ubuntu
it offers autocomplete suggestions like ubuntu
, ubuntu-debootstrap
and ubuntu-upstart
. When writing FROM ubuntu:a
it offers an autocomplete suggestions like ubuntu:artful
and ubuntu:artful-20170511.1
ReferenceURL : https://stackoverflow.com/questions/24481564/how-can-i-find-a-docker-image-with-a-specific-tag-in-docker-registry-on-the-dock
'program tip' 카테고리의 다른 글
Git merge --squash와 --no-commit의 차이점 (0) | 2020.12.31 |
---|---|
복합 키 Entity Framework 만들기 (0) | 2020.12.31 |
Bluebird로 Node의 child_process.exec 및 child_process.execFile 함수를 약속하는 방법은 무엇입니까? (0) | 2020.12.30 |
* ngFor에서 동적 ID를 설정하는 방법은 무엇입니까? (0) | 2020.12.30 |
내 onItemSelectedListener가 ListView에서 호출되지 않는 이유는 무엇입니까? (0) | 2020.12.30 |