How to get a list of images on docker registry v2

前端 未结 16 1760
孤城傲影
孤城傲影 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:21

    you can search on

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

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

    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

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

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

    This threads dates back a long time, the most recents tools that one should consider are skopeo and crane.

    skopeo supports signing and has many other features, while crane is a bit more minimalistic and I found it easier to integrate with in a simple shell script.

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

    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)

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

    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.

    0 讨论(0)
提交回复
热议问题