《原创》python定期清理docker中的无用镜像
2022/6/3 1:22:50
本文主要是介绍《原创》python定期清理docker中的无用镜像,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import os import sys def main(): member_pth = './member' txts = os.listdir(member_pth) member_images = [] # get all image-ID that not deleted from all member print('********** start collect images-id of members **********') for i in txts: with open(os.path.join(member_pth, i), 'r') as f: while 1: txt_line = f.readline() if not txt_line: break member_images.append(txt_line.strip('\n')) print(member_images) # get all image-ID in docker print('************* start collect images-id of system ***********') os.system('docker images -q > all-images.txt') all_images = [] with open('all-images.txt', 'r') as af: while 1 : txt_a = af.readline() if not txt_a: break all_images.append(txt_a.strip('\n')) print(all_images) print('************** start delete images that not belong to member ***********') for i in all_images: if i not in member_images: os.system('docker rmi -f {}'.format(i)) print('ID: {} is already deleted ......'.format(i)) if __name__ == '__main__': main()
这篇关于《原创》python定期清理docker中的无用镜像的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27docker容器内没有bash,怎么通过docker exec -it进入容器内部?-icode9专业技术文章分享
- 2024-12-26alpine构建的镜像无法使用docker exec -it 进入内部怎么办?-icode9专业技术文章分享
- 2024-12-24Docker环境部署资料详解
- 2024-12-24Docker环境部署教程:新手入门详解
- 2024-12-24Docker环境部署项目实战教程
- 2024-12-24Docker环境部署学习:初学者指南
- 2024-12-24Docker环境部署入门:新手必读指南
- 2024-12-20Docker部署资料:新手入门教程
- 2024-12-19Docker部署实战:新手入门教程
- 2024-12-19Docker部署教程:新手入门详解