Goglides Dev 🌱

Cover image for Docker list images in registry
Balkrishna Pandey
Balkrishna Pandey

Posted on

Docker list images in registry

Docker Registry is an essential tool for developers and teams using Docker. It offers a storage and distribution system for Docker images. In this guide, we will deep dive into the process of communicating with this registry, specifically how to list images and their tags, and how to run your local registry.

Setting Up the Local Docker Registry

Before communicating with a registry, you might want to run one locally. The DockerHub provides an image for the Docker Registry V2:

docker pull distribution/registry:master
Enter fullscreen mode Exit fullscreen mode

Creating a Docker Volume for Persistent Storage

Instead of manually creating a directory, we'll use Docker's built-in volume management:

docker volume create local-registry
Enter fullscreen mode Exit fullscreen mode

You should see the output:

local-registry
Enter fullscreen mode Exit fullscreen mode

Running the Local Registry with Docker Volume

Now, run the Docker Registry and mount the created volume:

docker run -d -p 5000:5000 -v local-registry:/var/lib/registry distribution/registry:master
Enter fullscreen mode Exit fullscreen mode

Registry is now running,

docker ps
Enter fullscreen mode Exit fullscreen mode

You should see the output:

CONTAINER ID   IMAGE                          COMMAND                  CREATED         STATUS         PORTS                    NAMES
de05269bc97b   distribution/registry:master   "registry serve /etc…"   7 seconds ago   Up 6 seconds   0.0.0.0:5000->5000/tcp   kind_johnson
Enter fullscreen mode Exit fullscreen mode

Communicating with the Registry

List All Repositories (Images)

curl -X GET http://localhost:5000/v2/_catalog
Enter fullscreen mode Exit fullscreen mode

Output:

{"repositories":[]}
Enter fullscreen mode Exit fullscreen mode

Now lets pull ubuntu image and push it to your local registry,

docker pull ubuntu
docker tag ubuntu localhost:5000/ubuntu 
docker push localhost:5000/ubuntu 
Enter fullscreen mode Exit fullscreen mode

List All Tags for a Specific (ubuntu) Repository

curl -X GET http://localhost:5000/v2/ubuntu/tags/list
Enter fullscreen mode Exit fullscreen mode

Output:

{"name":"ubuntu","tags":["latest"]}
Enter fullscreen mode Exit fullscreen mode

Handling Secure Registries

Bypassing SSL Certificate Verification

When dealing with SSL certificates that are self-signed or issued by a non-trusted certificate authority, curl will return an error. To bypass this SSL verification, you can use the -k or --insecure flags:

curl -k -X GET https://localhost:5000/v2/_catalog
Enter fullscreen mode Exit fullscreen mode

Authenticating Requests

If the registry requires authentication, specify the username and password using the -u option:

curl -X GET -u <user>:<pass> https://localhost:5000/v2/_catalog
Enter fullscreen mode Exit fullscreen mode

And for fetching tags:

curl -X GET -u <user>:<pass> https://localhost:5000/v2/ubuntu/tags/list
Enter fullscreen mode Exit fullscreen mode

Top comments (0)