How to get a list of images on docker registry v2

前端 未结 16 1759
孤城傲影
孤城傲影 2020-12-02 04:04

I\'m using docker registry v1 and I\'m interested in migrating to the newer version, v2. But I need some way to get a list of images present on registry; for example with re

相关标签:
16条回答
  • 2020-12-02 04:29

    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
    
    0 讨论(0)
  • 2020-12-02 04:31

    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

    0 讨论(0)
  • 2020-12-02 04:32

    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.

    0 讨论(0)
  • 2020-12-02 04:37

    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
    
    0 讨论(0)
提交回复
热议问题