Docker在移除图像后将其拉出,除最后一个图层外的所有图层均已存在

wswtfjt7  于 2023-03-17  发布在  Docker
关注(0)|答案(1)|浏览(105)

拉取前,docker images中的信息:

REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
weaveworks/weave-kube         2.5.2               f04a043bb67a        7 months ago        148MB
weaveworks/weave-npc          2.5.2               5ce48e0d813c        7 months ago        49.6MB
k8s.gcr.io/kube-proxy-amd64   v1.11.0             1d3d7afd77d1        18 months ago       97.8MB
k8s.gcr.io/pause              3.1                 da86e6ba6ca1        2 years ago         742kB

但是,当我试图下载一张图像时,它显示除了最后一层之外的所有层都已经存在:

$ docker pull image_name:s2-audio-1
s2-audio-1: Pulling from image_name:s2-audio-1
121er07f4eba: Already exists
0c8f4rew94dc: Already exists
198ef12987c0: Already exists
1pp1b5eaa295: Already exists
8a4fm1842a93: Already exists
3446a509a6e7: Already exists
10h6cedf3c5e: Already exists
0te381950737: Already exists
6gdf14004bd1: Already exists
88le96f02ad0: Already exists
udhb049fbae0: Already exists
llae95975878: Already exists
9fl1d0e8bd4e: Already exists
jd3b2c426fa1: Already exists
6j10b5462122: Already exists
21c258fef3cc: Already exists
0jzb3ee699a9: Already exists
zj019b962h6a: Already exists
04345388691c: Already exists
eyu517086e97: Pull complete
Digest: sha256:9wk43b75202a889711817b52e5979fg33ed387727a7a6eddc8e521d1da05ld2a
Status: Downloaded newer image for image_name:s2-audio-1

我猜Docker State有一些问题,所以我试图通过以下方式解决问题:

sudo service docker stop
sudo rm -rf /var/lib/docker
sudo service docker start

这样我就可以正常地拉image_name:s2-audio-1了。

s2-audio-1: Pulling from image_name:s2-audio-1
121er07f4eba: Pull complete
0c8f4rew94dc: Pull complete
198ef12987c0: Pull complete
1pp1b5eaa295: Pull complete
8a4fm1842a93: Pull complete
3446a509a6e7: Pull complete
10h6cedf3c5e: Pull complete
0te381950737: Pull complete
6gdf14004bd1: Pull complete
88le96f02ad0: Pull complete
udhb049fbae0: Pull complete
llae95975878: Pull complete
9fl1d0e8bd4e: Pull complete
jd3b2c426fa1: Pull complete
6j10b5462122: Pull complete
21c258fef3cc: Pull complete
0jzb3ee699a9: Pull complete
zj019b962h6a: Pull complete
04345388691c: Pull complete
eyu517086e97: Pull complete
Digest: sha256:9wk43b75202a889711817b52e5979fg33ed387727a7a6eddc8e521d1da05ld2a
Status: Downloaded newer image for image_name:s2-audio-1

但是,当我试图删除此图像:

Untagged: image_name:s2-audio-1
Untagged: image_name@sha256:9wk43b75202a889711817b52e5979fg33ed387727a7a6eddc8e521d1da05ld2a
Deleted: sha256:d7349f1dd8yhdffb55b9c68ec2f4573e6e45d6f22bd065e940d6e8f06627f586
Deleted: sha256:2da3218b4cd1a85e388k4b435411ac1082ce23571eeea4570a230583ee34795a

未标记和删除的图层数量比以前少了很多,应该是这样的:

$ docker rmi image_name:s2-audio-3
Untagged: image_name:s2-audio-3
Deleted: sha256:eds287df3d80dc048096dd67ecf09008b99dbe23ht8a6d4244e82ht9e0620c6d
Deleted: sha256:0d387c6877f0382a8d62474f1fdc3alo44cb1159fdcd3b7fdd9fb0c4f61d32a8
Deleted: sha256:d1b2f94b32ec9a4be182fcb4ef4919f439v6b6765975295654a3e594daa24646
Deleted: sha256:2f9uug161f8c01723367a21121797400261d41426a0dbd2a1c85828df7851bb8
Deleted: sha256:a6865f228367ce14548da56a9d9bbe5568sf6b30eb6de04bf46a758356d93280
Deleted: sha256:fc47aad0131dca88bd2ads792f238c577594a7b0e27f678cea0e64f447c94b44
Deleted: sha256:11e5f8ad0b20ebaa39c17273a859wr32a9260dafea5e513850ec56106ede679a
Deleted: sha256:cabf7d90af0bew5c5ce4965a8e994146fed9114f32b3da9bab321963c63ea308
Deleted: sha256:c7cfdc043db5f78arfg7a660f60642d8d6f4de770c10089f3dc5b3d989e856dd
Deleted: sha256:30a82effba73451b0c235859724995cebfe3g6574d286ffe5c2beb74150b977f
Deleted: sha256:7eae8b82dd96e5bde4c23a5868222c7eae05f2743c608d44dffdfbed54c56ef0
Deleted: sha256:b9ca36ae1e9e7e201802597f6e434adc5533sdsc90d9ab0476502b1cf5bd5ee4
Deleted: sha256:a765c11dsbbfc69f1089f96e55ed02a901e35c1f2834cebc790a2046fe5dcaf1

然后我尝试再次拉image_name:s2-audio-1,拉问题再次出现。(iidoEe.除了最后一层之外的所有层都已经存在。)
现在,Docker只会在我每次删除图像时删除和取消标记一个图层,其余的图层仍然保存在磁盘中,即使我使用docker images也是不可见的:

REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
weaveworks/weave-kube         2.5.2               f04a043bb67a        7 months ago        148MB
weaveworks/weave-npc          2.5.2               5ce48e0d813c        7 months ago        49.6MB
k8s.gcr.io/kube-proxy-amd64   v1.11.0             1d3d7afd77d1        18 months ago       97.8MB
k8s.gcr.io/pause              3.1                 da86e6ba6ca1        2 years ago         742kB

这让我很担心,看不见的层消耗了我大量的存储空间,而且没有合适的方法来删除它们。(一直使用sudo rm -rf /var/lib/docker并不是一个好主意。)

gcuhipw9

gcuhipw91#

运行docker image rm <image>(或等效的docker rmi <image>)实际上只是取消图像的标签并删除最后一层,其他层将留在原处,因为它们可能会被其他图像重用。
如果要删除这些“悬挂”图层(已标记图像不再使用的图层),可以使用docker image prune命令。
您可以通过运行以下命令 * 列出 * 悬挂层:

docker image ls --filter dangling=true

相关问题