development

docker registry v2에서 이미지 목록을 얻는 방법

big-blog 2020. 5. 14. 20:34
반응형

docker registry v2에서 이미지 목록을 얻는 방법


docker registry v1을 사용하고 있으며 최신 버전 인 v2로 마이그레이션하는 데 관심이 있습니다. 그러나 레지스트리에 이미지 목록을 표시하는 방법이 필요합니다. 예를 들어 레지스트리 v1을 사용하면 GET 요청을 실행할 수 http://myregistry:5000/v1/search?있으며 결과는 다음과 같습니다.

{
  "num_results": 2,
  "query": "",
  "results": [
    {
      "description": "",
      "name": "deis/router"
    },
    {
      "description": "",
      "name": "deis/database"
    }
  ]
}

그러나 공식 문서 에서 레지스트리의 이미지 목록을 얻는 것과 비슷한 것을 찾을 수 없습니다 . 새 버전 v2에서 수행하는 방법을 아는 사람이 있습니까?


Registry V2의 최신 버전 (2015-07-31 기준)의 경우 DockerHub 에서이 이미지얻을 수 있습니다 .

docker pull distribution/registry:master

모든 저장소 (효과적으로 이미지)를 나열하십시오.

curl -X GET https://myregistry:5000/v2/_catalog
> {"repositories":["redis","ubuntu"]}

저장소의 모든 태그를 나열하십시오.

curl -X GET https://myregistry:5000/v2/ubuntu/tags/list
> {"name":"ubuntu","tags":["14.04"]}

당신은 검색 할 수 있습니다

http : // <ip/hostname>: <port>/ v2 / _catalog


카탈로그 받기

기본적으로 레지스트리 API는 카탈로그의 100 항목을 반환하며 코드는 다음과 같습니다.

레지스트리 API를 말릴 때 :

curl --cacert domain.crt https://your.registry:5000/v2/_catalog

그것은 다음과 같습니다.

curl --cacert domain.crt https://your.registry:5000/v2/_catalog?n=100

이것은 페이지 매김 방법입니다.

항목의 합이 100을 초과하면 두 가지 방법으로 수행 할 수 있습니다.

첫째 : 더 큰 숫자를 줘

curl --cacert domain.crt https://your.registry:5000/v2/_catalog?n=2000

Sencond : 다음 링커 URL 구문 분석

curl --cacert domain.crt https://your.registry:5000/v2/_catalog

응답 헤더에 포함 된 링크 요소 :

curl --cacert domain.crt https://your.registry:5000/v2/_catalog

응답 헤더 :

Link: </v2/_catalog?last=pro-octopus-ws&n=100>; rel="next"

링크 요소에는이 요청의 마지막 항목이 있으며 다음 '페이지'를 요청할 수 있습니다.

curl --cacert domain.crt https://your.registry:5000/v2/_catalog?last=pro-octopus-ws

응답 헤더에 링크 요소 가 포함 된 경우 루프 에서 수행 할 수 있습니다 .

이미지 받기

카탈로그 결과를 얻으면 다음과 같습니다.

{ "repositories": [ "busybox", "ceph/mds" ] }

모든 카탈로그에서 이미지를 얻을 수 있습니다.

curl --cacert domain.crt https://your.registry:5000/v2/busybox/tags/list

보고:

{"name":"busybox","tags":["latest"]}


The latest version of Docker Registry available from https://github.com/docker/distribution supports Catalog API. (v2/_catalog). This allows for capability to search repositories

If interested, you can try docker image registry CLI I built to make it easy for using the search features in the new Docker Registry distribution (https://github.com/vivekjuneja/docker_registry_cli)


This has been driving me crazy, but I finally put all the pieces together. As of 1/25/2015, I've confirmed that it is possible to list the images in the docker V2 registry ( exactly as @jonatan mentioned, above. )

I would up-vote that answer, if I had the rep for it.

Instead, I'll expand on the answer. Since registry V2 is made with security in mind, I think it's appropriate to include how to set it up with a self signed cert, and run the container with that cert in order that an https call can be made to it with that cert:

This is the script I actually use to start the registry:

sudo docker stop registry
sudo docker rm -v registry
sudo docker run -d \
  -p 5001:5001 \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v /data/registry:/var/lib/registry \
  -v /root/certs:/certs \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ 
  -e REGISTRY_HTTP_DEBUG_ADDR=':5001' \
  registry:2.2.1

This may be obvious to some, but I always get mixed up with keys and certs. The file that needs to be referenced to make the call @jonaton mentions above**, is the domain.crt listed above. ( Since I put domain.crt in /root, I made a copy into the user directory where it could be accessed. )

curl --cacert ~/domain.crt https://myregistry:5000/v2/_catalog
> {"repositories":["redis","ubuntu"]}

**The command above has been changed: -X GET didn't actually work when I tried it.

Note: https://myregistry:5000 ( as above ) must match the domain given to the cert generated.


We wrote a CLI tool for this purpose: docker-ls It allows you to browse a docker registry and supports authentication via token or basic auth.


Please see @jonathan's answer below, or the registry API docs here: https://docs.docker.com/registry/spec/api/

If you search for "listing" you'll see that the support was added in version e.


Install registry:2.1.1 or later (you can check the last one, here) and use GET /v2/_catalog to get list.

https://github.com/docker/distribution/blob/master/docs/spec/api.md#listing-repositories

Lista all images by Shell script example: https://gist.github.com/OndrejP/a2386d08e5308b0776c0


Here is a nice little one liner (uses JQ) to print out a list of Repos and associated tags.

If you dont have jq installed you can use: brew install jq

# This is my URL but you can use any
REPO_URL=10.230.47.94:443

curl -k -s -X GET https://$REPO_URL/v2/_catalog \
 | jq '.repositories[]' \
 | sort \
 | xargs -I _ curl -s -k -X GET https://$REPO_URL/v2/_/tags/list

If some on get this far.

Taking what others have already said above. Here is a one-liner that puts the answer into a text file formatted, json.

curl "http://mydocker.registry.domain/v2/_catalog?n=2000" | jq . - > /tmp/registry.lst

This looks like

{
  "repositories": [
    "somerepo/somecontiner",
    "somerepo_other/someothercontiner",
 ...
  ]
}

You might need to change the `?n=xxxx' to match how many containers you have.

Next is a way to automatically remove old and unused containers.


I had to do the same here and the above works except I had to provide login details as it was a local docker repository.

It is as per the above but with supplying the username/password in the URL.

curl -k -X GET https://yourusername:yourpassword@theregistryURL/v2/_catalog

It comes back as unformatted JSON.

I piped it through the python formatter for ease of human reading, in case you would like to have it in this format.

curl -k -X GET https://yourusername:yourpassword@theregistryURL/v2/_catalog | python -m json.tool

Using "/v2/_catalog" and "/tags/list" endpoints you can't really list all the images. If you pushed a few different images and tagged them "latest" you can't really list the old images! You can still pull them if you refer to them using digest "docker pull ubuntu@sha256:ac13c5d2...". So the answer is - there is no way to list images you can only list tags which is not the same


Docker search registry v2 functionality is currently not supported at the time of this writing. See discussion since Feb 2015: "propose registry search functionality #206" https://github.com/docker/distribution/issues/206

I wrote a script that you can find: https://github.com/BradleyA/Search-docker-registry-v2-script.1.0 It is not pretty but it gets the information needed from the private registry.


I wrote an easy-to-use command line tool for listing images in various ways (like list all images, list all tags of those images, list all layers of those tags).

It also allows you to delete unused images in various ways, like delete only older tags of a single image or from all images etc. This is convenient when you are filling your registry from a CI server and want to keep only latest/stable versions.

It is written in python and does not need you to download bulky big custom registry images.


Here's an example that lists all tags of all images on the registry. It handles a registry configured for HTTP Basic auth too.

THE_REGISTRY=localhost:5000

# Get username:password from docker configuration. You could
# inject these some other way instead if you wanted.
CREDS=$(jq -r ".[\"auths\"][\"$THE_REGISTRY\"][\"auth\"]" .docker/config.json | base64 -d)

curl -s --user $CREDS https://$THE_REGISTRY/v2/_catalog | \
    jq -r '.["repositories"][]' | \
    xargs -I @REPO@ curl -s --user $CREDS https://$THE_REGISTRY/v2/@REPO@/tags/list | \
    jq -M '.["name"] + ":" + .["tags"][]'

Explanation:

  • extract username:password from .docker/config.json
  • make a https request to the registry to list all "repositories"
  • filter the json result to a flat list of repository names
  • for each repository name:
  • make a https request to the registry to list all "tags" for that "repository"
  • filter the stream of result json objects, printing "repository":"tag" pairs for each tag found in each repository

Since each registry runs as a container the container ID has an associated log file ID-json.log this log file contains the vars.name=[image] and vars.reference=[tag]. A script can be used to extrapolate and print these. This is perhaps one method to list images pushed to registry V2-2.0.1.

참고URL : https://stackoverflow.com/questions/31251356/how-to-get-a-list-of-images-on-docker-registry-v2

반응형