Reputation: 9574
Is there a way to let Docker list all the available image versions that can be downloaded?
Let's say I want to get the latest version of Apache, then I could type this:
docker pull httpd:latest
Now, if I am interested in a particular version, I could type this:
docker pull httpd:2.4.34
In order to be able to do that though, I need to know that there is a version 2.4.34
available. Now, is there a way to list available versions? I am looking for something similar to this:
docker list httpd versions
and I would like to have a response similar to this:
2.4.34
2.4.32
2.4.29
2.2.34
...
Upvotes: 7
Views: 8411
Reputation: 186
We have several hubs, sometimes we need to get all available images and their tags.
The Python solution looks like this.
import requests
session = requests.session()
hubs = [
'qwerty:[email protected]',
'qwerty1:[email protected]'
]
for hub in hubs:
print(hub)
repositories = session.get(f'https://{hub}/v2/_catalog').json()['repositories']
for i in repositories:
print(session.get(f'https://{hub}/v2/{i}/tags/list').json())
print()
Upvotes: 0
Reputation: 264156
This is done using the OCI Tag Listing API. A shell script to call that on Docker Hub looks like:
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
-u "${username}:${password}" \
| jq -r '.token')
curl -H "Authorization: Bearer $token" \
-s "https://registry-1.docker.io/v2/${repo}/tags/list" | jq .
However, I'd recommend using one of the various tools designed for this that will help with authentication (or anonymous access) and pagination (when the number of tags exceeds the registry limit). Here are a few tools that I'm ware of:
Crane from Google:
$ crane ls busybox
1
1-glibc
1-musl
1-ubuntu
1-uclibc
1.21-ubuntu
1.21.0-ubuntu
1.23
1.23.2
1.24
1.24-glibc
1.24-musl
1.24-uclibc
...
ORAS from Microsoft:
$ oras repo tags docker.io/library/busybox
1
1-glibc
1-musl
1-ubuntu
1-uclibc
1.21-ubuntu
1.21.0-ubuntu
1.23
1.23.2
1.24
1.24-glibc
1.24-musl
1.24-uclibc
...
Skopeo from RedHat:
$ skopeo list-tags docker://docker.io/library/busybox
{
"Repository": "docker.io/library/busybox",
"Tags": [
"1",
"1-glibc",
"1-musl",
"1-ubuntu",
"1-uclibc",
"1.21-ubuntu",
"1.21.0-ubuntu",
"1.23",
"1.23.2",
"1.24",
"1.24-glibc",
"1.24-musl",
"1.24-uclibc",
...
regctl from myself:
$ regctl tag ls busybox
1
1-glibc
1-musl
1-ubuntu
1-uclibc
1.21-ubuntu
1.21.0-ubuntu
1.23
1.23.2
1.24
1.24-glibc
1.24-musl
1.24-uclibc
...
Upvotes: 0
Reputation: 1166
Use skopeo
brew install skopeo
skopeo list-tags docker://docker.io/redis
skopeo list-tags docker://container-registry.oracle.com/database/free
This will return a JSON object showing all of the available image versions
Upvotes: 0
Reputation: 2239
I don't know if docker supports this, but podman
has --list-tags
:
podman search nginx --list-tags
which shows (truncated):
NAME TAG
docker.io/library/nginx 1
docker.io/library/nginx 1-alpine
docker.io/library/nginx 1-alpine-perl
docker.io/library/nginx 1-perl
docker.io/library/nginx 1.10
...
docker.io/library/nginx 1.11.12
docker.io/library/nginx 1.11.12-alpine
docker.io/library/nginx 1.11.13
The --limit
paramater can come handy with --list-tags
when there are a lot of results. podman search --list-tags --limit 1000 docker.io/library/mariadb
displays 365 results...
Upvotes: 2
Reputation: 2533
There is an API endpoint for this action which is explained here:
https://docs.docker.com/registry/spec/api/#listing-image-tags
The endpoint itself is the following:
/v1/repositories/(namespace)/(repository)/tags
So you can run the following command in order to access it:
curl -u <username>:<password> https://registry-1.docker.io/v1/repositories/<username>/<image_name>/tags
Upvotes: 4