Skip to content

Instantly share code, notes, and snippets.

@xiaket
Created March 20, 2017 05:28
Show Gist options
  • Save xiaket/d6e0a77c5f7bda8753057b322b06355d to your computer and use it in GitHub Desktop.
Save xiaket/d6e0a77c5f7bda8753057b322b06355d to your computer and use it in GitHub Desktop.
Get the list of images and tags for a Docker Hub repo
import json
import sys
import requests
AUTH ={
'username': "xiaket",
'password': "YourPasswordHere",
}
def login():
response = requests.post(
'https://hub.docker.com/v2/users/login/',
headers={'Content-type': 'application/json'},
data=json.dumps(AUTH),
)
if not response.ok:
sys.stderr.write("Login failed: %s\n" % response.text['detail'])
sys.exit(1)
return response.json()['token']
def get_repo_images(repo, token):
return requests.get(
'https://hub.docker.com/v2/repositories/%s/tags/?page_size=500' % repo,
headers={'Authorization': 'JWT %s' % token},
)
def main():
token = login()
get_repo_images('gitlab/gitlab-ce', token)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment