美文网首页程序员
shell脚本批量删除docker镜像

shell脚本批量删除docker镜像

作者: 南南宫问天 | 来源:发表于2020-04-27 11:42 被阅读0次

平时我们下载了很多镜像.但这些镜像已经很老了,我们需要把原来的镜像删除,但如果镜像很多的话,手动删除会特别麻烦,我们可以写个脚本批量删除

[root@server script]# cat docker_deleteimage.sh 
#!/bin/bash
for i in `docker images | grep -v "IMAGE" | awk '{print $3}'` ##提取出镜像id
 do 
    {
    docker rmi -f $i &>/dev/null  ##删除镜像
    echo "docekr delete $i complete"
    } &
done
wait
echo -e "\e[1;31mdelete complete \e[0m" 
[root@server script]# docker images  ##现在这里有很多镜像
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
172.16.210.30:5000/rancher/server            v1.6.5              f89070da7581        2 years ago         984.9 MB
172.16.210.30:5000/rancher/scheduler         v0.8.2              690ef14a99b7        2 years ago         241.9 MB
172.16.210.30:5000/rancher/agent             v1.2.5              ef5fea38dbe6        2 years ago         237.1 MB
172.16.210.30:5000/rancher/network-manager   v0.7.4              787fc137ac53        2 years ago         248.8 MB
172.16.210.30:5000/rancher/metadata          v0.9.2              d46f30a656e0        2 years ago         251.5 MB
172.16.210.30:5000/rancher-net               v0.11.3             9495baae8faf        2 years ago         267.3 MB
172.16.210.30:5000/rancher/dns               v0.15.1             af5509fe436b        2 years ago         239.8 MB
172.16.210.30:5000/rancher/healthcheck       v0.3.1              10710b438de7        3 years ago         383.9 MB
172.16.210.30:5000/rancher/net_holder        latest              665d9f6e8cc1        3 years ago         267.2 MB
172.16.210.30:5000/registry                  latest              c9bd19d022f6        3 years ago         33.27 MB
docker.io/registry                           latest              c9bd19d022f6        3 years ago         33.27 MB
[root@server script]# sh docker_deleteimage.sh  ##执行成功
docekr delete c9bd19d022f6 complete
docekr delete c9bd19d022f6 complete
docekr delete f89070da7581 complete
docekr delete 690ef14a99b7 complete
docekr delete ef5fea38dbe6 complete
docekr delete af5509fe436b complete
docekr delete 10710b438de7 complete
docekr delete d46f30a656e0 complete
docekr delete 9495baae8faf complete
docekr delete 665d9f6e8cc1 complete
docekr delete 787fc137ac53 complete
delete complete 
[root@server script]# docker images  ##删除成功
REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
[root@server script]# 

相关文章

网友评论

    本文标题:shell脚本批量删除docker镜像

    本文链接:https://www.haomeiwen.com/subject/vmcywhtx.html