docker-删除none镜像

我们经常会遇到none的镜像 ,就像下面的图片里这种。

我们可以直接删掉 docker rmi 镜像ID

docker rmi $(docker images | grep "none" | awk '{print $3}') 

如果有依赖关系的,像下面这种。

bash-3.2# docker rmi 7df0e1473499
Error response from daemon: conflict: unable to delete 7df0e1473499 (cannot be forced) - image has dependent child images

有镜像依赖于当前的镜像,我们可以分析要删除的依赖关系 docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}'  $(docker image ls -q --filter since=镜像ID)  按照tag 镜像ID 父镜像ID 

bash-3.2# docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}'  $(docker image ls -q --filter since=7df0e1473499)
[basic_php_dev:2] sha256:fb47798781784b80ce1cbcb4fe02671d5b7fbdd0141f5235082b0bf3ab2c2ea6 sha256:a8a060f499ef5c4df607425c1d5a0746fad2d482c244876dccabb0ac557913ff
[] sha256:344e1ada14dac2850c5f7ae9a44df7ca35147af6e6fe6c13d96b57db9ee542c6 sha256:7df0e14734998e79f29370b414ba002d41a3ea0f0f3c2966a7eaf4be76f454a4

我们从前面的记录开始 删掉无用的镜像ID 有多个就都删掉 

docker rmi fb47798781784b80ce1cbcb4fe02671d5b7fbdd0141f5235082b0bf3ab2c2ea6
Untagged: basic_php_dev:2
Deleted: sha256:fb47798781784b80ce1cbcb4fe02671d5b7fbdd0141f5235082b0bf3ab2c2ea6
Deleted: sha256:2c11ed80257706a0f0ace2531b7dd338c7db07a14d9543ca025c64124ecdb1da
Deleted: sha256:a8a060f499ef5c4df607425c1d5a0746fad2d482c244876dccabb0ac557913ff
Deleted: sha256:43ab27b93b2c34a0b17c984221472eacab290d40bb302e0d1d1586010636ee0c
Deleted: sha256:ac54eeeab742cf480d3b9f5a7d427a10d2881c1bfb0f75070507f70a5bf33ec9
Deleted: sha256:b1aa850d693f3eac20c0e76269f662fa480b02c2eedfed0d8114a3200550b008

我是用Dockfile创建镜像时,前面失败了几次,发现了很多无用镜像,所以创建镜像失败时,要及时删掉无用镜像,确定很干净的情况下,在运行容器, 否则后面要清理容器镜像都要删掉。

还有一个是,如果平常用基础镜像运行一个容器,之后加点东西,保存镜像,每次加了东西就保存,这样是非常不推荐的,日后清理也很蛋疼。

 

你可能感兴趣的:(docker)