To list local images that are stored in your Docker registry, the specific command you use depends on whether you are referring to images stored locally on your Docker host or images stored in a local Docker registry service.
Listing Images on a Docker Host
If you want to list all Docker images stored locally on your Docker host, you can use the following command:
docker images
This will provide you with a list of images, including their repository name, tag, image ID, creation date, and size.
Listing Images in a Local Docker Registry
If you are running a local Docker registry, you’ll need to query the registry API to get a list of images hosted there. Assuming your local Docker registry is running at http://localhost:5000, you can use curl to query the registry:
Step 1: List Repositories
To get a list of all repositories in your local Docker registry:
curl -X GET http://localhost:5000/v2/_catalog
This will return a JSON object listing all repositories. For example:
{
"repositories": [
"my-application",
"another-application"
]
}
Step 2: List Tags for a Repository
To list all tags for a specific repository (e.g., my-application):
curl -X GET http://localhost:5000/v2/my-application/tags/list
This will return a JSON object with all tags for the specified repository. For example:
{
"name": "my-application",
"tags": [
"latest",
"v1.0",
"v1.1"
]
}
Using jq for Pretty Printing
You can use the jq tool to pretty-print JSON responses from curl:
# List repositories
curl -X GET http://localhost:5000/v2/_catalog | jq
# List tags for a specific repository
curl -X GET http://localhost:5000/v2/my-application/tags/list | jq
Complete Example Script
The following script summarizes the steps and consolidates them into an easy-to-use format:
#!/bin/bash
# Define the local Docker registry URL
REGISTRY_URL="http://localhost:5000"
# List all repositories in the local Docker registry
echo "Fetching all repositories from the local Docker registry..."
repos=$(curl -s ${REGISTRY_URL}/v2/_catalog | jq -r '.repositories[]')
for repo in $repos; do
echo "Repository: $repo"
# List all tags for each repository
tags=$(curl -s ${REGISTRY_URL}/v2/$repo/tags/list | jq -r '.tags[]')
for tag in $tags; do
echo " Tag: $tag"
done
done
Save this script to a file (e.g., list_local_registry_images.sh), make it executable (chmod +x list_local_registry_images.sh), and then run it (./list_local_registry_images.sh).
These commands and scripts will help you list images stored either locally on your Docker host or in your local Docker registry.