REST API authentication for hub

Iā€™m trying to improve docker-tag-naming to support private repositories. To do this I need to be able to authenticate and then retrieve image tags.

The docs at https://docs.docker.com/reference/api/docker-io_api/ are not clear on how I should generate a token to access a private repo information, could someone help me it out?

Extra brownie points if you answer only with curl commands :+1:

DONE!

import requests
import json

index_endpoint = 'https://registry.hub.docker.com'
namespace = 'andresriancho'
repos = 'private'
user_credentials = ('andresriancho', 'long-password-not-shown-in-forums')


resp = requests.get('{0}/v1/repositories/{1}/{2}/images'.format(index_endpoint, namespace, repos),
                    auth=tuple(user_credentials),
                    headers={'X-Docker-Token': 'true'})

token = resp.headers.get('x-docker-token')
endpoint = resp.headers.get('x-docker-endpoints')

resp = requests.get('https://{0}/v1/repositories/{1}/{2}/tags'.format(endpoint, namespace, repos),
                    headers={'Authorization': 'Token ' + token})

print(json.dumps(resp.json(), indent=4))
1 Like

Cool script! Problem: it only retrieves 6 of the tags from my private repository. Have you run into this at all? I cannot figure out why.

I have the same problem with your docker-tag-naming library. Running the script above connects and retrieves proper tags for the image I specify, but appears limited to 6 results. It seems to have some kind of pagination or limit going on, but I cannot find any reference to pagination parameters in the v1 API documentation.