如果没有标签/ <无>标签,则无法删除泊坞窗图像

时间:2015-07-28 21:12:32

标签: awk grep docker delete-file image-file

我正在使用docker,我发现当我运行

<none>

我有大量没有标签的图片,或者至少它们有

标签
docker rmi -f $(docker images -a | grep "^<none>" | awk '{print $3}')

这些浪费了我磁盘上的太多空间,现在df -h告诉我我的根已经满了。

我潜伏在互联网上,发现

Error: response from daemon: Conflict, <id> wasn't deleted
Error: response from daemon: Conflict, <id> wasn't deleted 
Error: response from daemon: Conflict, <id> wasn't deleted
Error: response from daemon: Conflict, <id> wasn't deleted 
etc...
Error: failed to remove images: [<list of all the image ids that I want gone>]

至少会遍历所有无关,但随后我会得到一大堆错误信息。

FrameLayout

这有点令人讨厌。有谁知道这些没有标记的图像是什么,为什么我的命令没有摆脱它们?

2 个答案:

答案 0 :(得分:5)

每当您构建新版本的标记图像时(例如,运行docker build -t foo .,更改Dockerfile中的内容,然后再次运行该命令),旧图像不会被删除;它只是把它的标签带走了。您看到的<none>是没有任何标签的图像,您可以通过指定图像ID(fe336c4cdb2f或其他)来在命令中引用它们。您可以通过将这些ID传递给docker rmi来删除它们,或者您可以这样做:

docker images -f dangling=true -q | xargs -r docker rmi

如果您仍然收到有关无法删除图片的错误消息,则可能是仍有容器悬挂使用这些旧图像;通过运行docker ps -a进行检查。

答案 1 :(得分:3)

Those <none> in REPOSITORY when you specifically do docker images -a are not meant to be deleted. Those are the internal layers that make up your image.

As suggested by @jwodder, you should delete the <none>ones which appear when you do docker images ( Note: I did not do -a ). If you see <none> in REPOSITORY when you do docker images, then you could do:
docker rmi -f $(docker images -f dangling=true -q)

If your disk space is full, try removing the images that you do not need and see when you do docker images, not with -a.