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
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
You should see the output:
local-registry
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
Registry is now running,
docker ps
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
Communicating with the Registry
List All Repositories (Images)
curl -X GET http://localhost:5000/v2/_catalog
Output:
{"repositories":[]}
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
List All Tags for a Specific (ubuntu) Repository
curl -X GET http://localhost:5000/v2/ubuntu/tags/list
Output:
{"name":"ubuntu","tags":["latest"]}
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
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
And for fetching tags:
curl -X GET -u <user>:<pass> https://localhost:5000/v2/ubuntu/tags/list
Top comments (0)