The previous article said how to build a private warehouse, but after the warehouse was set up, it was not convenient to maintain the mirrors in the warehouse, Docker officially did not have a good command line interface to use, but provided APIs that could be used to view and remove mirrors by invoking these APIs, but these APIs are really hard to use, So I found out that there's an Open-source Python tool that can do that. installation
First download the latest Python script from the website below, just download the registry.py file. Https://github.com/andrey-pohilko/registry-cli
Installing a dependent third party package
$ sudo pip install requests
Configuration
To enable mirroring of the Docker warehouse to be deleted, you need to modify the warehouse configuration file, and on CentOS7 the profile path is:/etc/docker-distribution/registry/config.yml. Need to add in file
Storage: ...
Delete:
enabled:true
The modified file is similar to the following:
$ cat/etc/docker-distribution/registry/config.yml
version:0.1
log:
fields:
service:registry
Storage:
cache:
layerinfo:inmemory
filesystem:
rootdirectory:/var/lib/registry
Delete:
enabled:true
http:
Addr: 5000
The warehouse service needs to be restarted after the modification is complete.
$ sudo systemctl restart Docker-distribution.service
Use
First look at what mirrors are in the warehouse
$ python registry.py-r http://localhost:5000
To test the need, we first create a few mirrors
$ sudo docker pull BusyBox
$ sudo docker tag busybox:latest localhost:5000/kongxx/busybox:v1
$ sudo docker push lo Calhost:5000/kongxx/busybox:v1
$ sudo docker tag busybox:latest localhost:5000/kongxx/busybox:v2
$ sudo Docker push Localhost:5000/kongxx/busybox:v2
$ sudo docker tag busybox:latest localhost:5000/kongxx/busybox:v3
$ sudo docker push Localhost:5000/kongxx/busybox:v3
Look at the mirrors in the warehouse again.
$ python registry.py-r http://localhost:5000
---------------------------------
Image:kongxx/mybusybox
tag:v1
tag:v2
tag:v3
---------------------------------
Image: ...
You can see that there is already a three tag of a mirror. Now let's remove the mirrored tag
# Remove Mirror tag, but default will retain 10
$ python registry.py-r http://localhost:5000-i kongxx/busybox-d
# Remove all tag $ for mirrors
Python registry.py-r http://localhost:5000-i kongxx/busybox--delete-all
# Remove Mirror tag, keep 1
$ python Registry.py-r http://localhost:5000-i kongxx/busybox-d--num 1
After removing all mirror tags, let's check that the mirror does not include any tag, but the mirror still exists
$ python registry.py-r http://localhost:5000
---------------------------------
Image:kongxx/busybox
No tags!
To completely remove a mirror at this point, you can delete the mirrored directory in the following directory, which is defined in the/etc/docker-distribution/registry/config.yml file
/var/lib/registry/docker/registry/v2/repositories/<image>
Then run the Docker Warehouse command garbage-collect command to clean up.
$ sudo Registry garbage-collect/etc/docker-distribution/registry/config.yml