docker实现重新打tag并删除原tag的镜像
docker镜像id是唯一的,可以物理性的标明一个镜像,repository:tag可以有多个,但是也不会重复,也是唯一的。
要重新打tag的话,语法是:
docker tag imageId repository:newTag
比如将这个centos:7重新打tag为centos7:base
此时仓库中有两个镜像,镜像id相同,只是多了一个tag标签,也就是多了一个引用。删除不需要的引用即可,删除时必须用tag删除,用镜像id删除会物理性的删除镜像,这两个引用会同时被删除掉。
当然,打tag的时候也可以使用这样的语法:
docker tag repository:tag repository:newTag
补充知识:docker遇到问题一:同一镜像有多个Tag情况下,执行 docker rmi 镜像ID 指令无法删除
镜像列表
Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE runoob/centos 6.7 4994f1f799c7 2 days ago 191MB runoob/centos dev 4994f1f799c7 2 days ago 191MB tomcat latest da0729cd9201 2 days ago 463MB
删除镜像
Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker rmi 4994f1f799c7
Error response from daemon: conflict: unable to delete 4994f1f799c7 (must be forced) - image is referenced in multiple repositories
删除方法一
docker rmi -f 镜像ID
如下所示:
Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker rmi -f 4994f1f799c7 Untagged: runoob/centos:6.7 Deleted: sha256:4994f1f799c7c9241c23055ecc7335c074caaa96243dcc665d1c1836216c34f2 Deleted: sha256:6829bdaf30b11efab68c0ae473690ae1637830a560487ce07ad08988484c0987 Deleted: sha256:fd54ea270ce8e890023eaba2a72eff187d27f71f3ffea9e11e9684de8ac9606a Deleted: sha256:ece17abd46a222b2fa35f1e18a981092605453c258dceca6919e3572ab4f1fbf Deleted: sha256:b59b8f6f9d682eeb94a3628fded0325e9d43664fdd26651971a6fc4bd34bc3ca Deleted: sha256:71c39bd52e1858772c19aac2b18203dca9a02f6a07a4cef54099ecd14734da83 Deleted: sha256:6ff1dc40fd96eebca0785a047794a83f3c954e4949c350fbd0661ed0f7ed8c96 Deleted: sha256:19efa1023a08e6d4014cea1821fe9f3b169eed3c11397460fb19db1d22b69fb2 Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest da0729cd9201 2 days ago 463MB
docker rmi : 删除本地一个或多少镜像。
语法
docker rmi [OPTIONS] IMAGE [IMAGE…]
OPTIONS说明:
-f : 强制删除;
–no-prune : 不移除该镜像的过程镜像,默认移除;
删除方法二
docker rmi repository:tag
如下所示:
Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker rmi runoob/centos:dev Untagged: runoob/centos:dev Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE runoob/centos 6.7 4994f1f799c7 2 days ago 191MB tomcat latest da0729cd9201 2 days ago 463MB Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker rmi runoob/centos:6.7 Untagged: runoob/centos:6.7 Cappuccinooos-MacBook-Pro:.docker Cappuccinooo$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest da0729cd9201 2 days ago 463MB
以上这篇docker实现重新打tag并删除原tag的镜像就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
下一篇:Docker 制作镜像Dockerfile和commit操作