docker如何物理删除私有仓库中的镜像或者tag

https://stackoverflow.com/questions/25436742/how-to-delete-images-from-a-private-docker-registry

如果我们只是删除某一个tag,是不会直接删除物理镜像的。

简单来说:

第一步,确保配置里面允许删除

/etc/docker/registry/config.yml

delete:
    enabled: true

第二步,直接调用删除脚本

https://github.com/burnettk/delete-docker-registry-image

PS:试过官方的delete api,实现是错误的,无法删除成功。

安装

sudo apt-get install python python-pip
sudo pip install requests
curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee /usr/local/bin/delete_docker_registry_image >/dev/null
sudo chmod a+x /usr/local/bin/delete_docker_registry_image
curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/clean_old_versions.py | sudo tee /usr/local/bin/clean_old_versions >/dev/null
sudo chmod a+x /usr/local/bin/clean_old_versions

确定docker registry位置(注意,通过docker启动,可以直接在host上执行,给volume且有权限即可)

export REGISTRY_DATA_DIR=/home/coder4/docker_data/docker_registry/registry/docker/registry/v2

删除某个镜像

# dryRun delete tag
delete_docker_registry_image --image eureka-server:build_7 --dry-run
# need shutdown registry
delete_docker_registry_image --image eureka-server:build_7

# dryRun delete whole image
delete_docker_registry_image --image eureka-server --dry-run
# need shutdown registry
delete_docker_registry_image --image eureka-server

清理旧的镜像

# clean all image , keep last 3
clean_old_versions. --image '^.*' -l 3 --registry-url http://docker.coder4.com:5000/

 

 

 

Leave a Reply

Your email address will not be published.