Skip to content

Instantly share code, notes, and snippets.

@davidthewatson
Created March 12, 2021 15:34
Show Gist options
  • Select an option

  • Save davidthewatson/d717af6d34f62d8d933635b5b6c23e2f to your computer and use it in GitHub Desktop.

Select an option

Save davidthewatson/d717af6d34f62d8d933635b5b6c23e2f to your computer and use it in GitHub Desktop.

Revisions

  1. davidthewatson created this gist Mar 12, 2021.
    23 changes: 23 additions & 0 deletions delete_dockerhub.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/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