Skip to content

Instantly share code, notes, and snippets.

@davidthewatson
Created March 12, 2021 15:34
Show Gist options
  • Save davidthewatson/d717af6d34f62d8d933635b5b6c23e2f to your computer and use it in GitHub Desktop.
Save davidthewatson/d717af6d34f62d8d933635b5b6c23e2f to your computer and use it in GitHub Desktop.
#!/bin/bash
# get username and password
echo "Username?"
read UNAME
echo "Password?"
read UPASS
echo "This will delete ever repo in your dockerhub. Ctrl-C to end."
read
set -e
echo
# aquire token
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
# get list of repositories for the user account
REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/?page_size=100 | jq -r '.results|.[]|.name')
# delete every repo in list
for i in ${REPO_LIST}
do
curl -X DELETE -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/
done
@davidthewatson
Copy link
Author

Every now and again I need to clear my dockerhub of cruft. That's everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment