How remove docker image/tag from Docker Hub

2020/04/20 18:06
阅读数 195

In daily development work, we often hope to quickly clean the problematic image from the docker hub, but manual operation is very time-consuming and laborious, so is there a good way? With this purpose, I checked a lot of information, and later found that a docker image named lumir/remove-dockerhub-tag can help us handle this work. Next, let's show our friends how to use this tool.


lwk@qwfys:~$ docker run --rm lumir/remove-dockerhub-tag --user qwfys --password ***** lanzhou/user-business:0.0.1.release
Unable to find image 'lumir/remove-dockerhub-tag:latest' locally
latest: Pulling from lumir/remove-dockerhub-tag
000eee12ec04: Pull complete 
ddc2d83f8229: Pull complete 
3ae1660fa0d9: Pull complete 
ef709117d3d3: Pull complete 
487a0421e8fa: Pull complete 
0567bf350aaf: Pull complete 
bd35eb6f3933: Pull complete 
0b4e338b89ca: Pull complete 
56ac5d14ba19: Pull complete 
Digest: sha256:9d5a167f76969cb22059f6accd191329856891cac2dcac5b2bfae84f746f1b4b
Status: Downloaded newer image for lumir/remove-dockerhub-tag:latest
removed: lanzhou/user-business:0.0.1.release

After an actual review, we found that the relevant work has indeed been completed. So, how does this tool work? With this question, let's take a closer look.First, let's go to its official website. On the docker hub, we found its official website.

在这里插入图片描述 在这里插入图片描述 Here, we see that it is done through a python script, so what does this python script do, we find it on the official website of github through the github link given on the official website. 在这里插入图片描述 On its github official website, we found this python script file named, whose contents are as follows:

import requests
import argparse
import re

parser = argparse.ArgumentParser()
parser.add_argument('--user', required=True, help='dockerhub username')
parser.add_argument('--password', required=True, help='dockerhub password')
parser.add_argument('image', nargs='+', help='org/image:tag')
args = parser.parse_args()

login = {"username": args.user, "password": args.password}
token ="", data = login).json()['token']

p = re.compile('(.+)\/(.+):(.+)')
for image in args.image:
    m = p.match(image)
    if not m:
        print('invalid image indetifier "{}"'.format(image))
        org =
        name =
        tag =
        r = requests.delete(f'{org}/{name}/tags/{tag}/', headers={"Authorization": f'JWT {token}'})
        if r.status_code == 204:
            print(f'removed: {image}')
            print(f'failed to remove "{image}": {r.text}')

Through the python script, we found that this gadget completed the corresponding work through the http api provided by docker hub.We also found that there are many such gadgets, and their principles are similar. For example, the two docker images named gliderlabs/dockerhub-tag and lazyfrosch/registry-cleanup are quite good. If you are interested, you can play with them.




0 收藏
0 评论
0 收藏