删除同名的docker镜像
服务器存储多个具有相同名称但具有不同标签的 docker 映像,我找到了一个很好的命令,它将搜索具有相同名称但具有不同标签的 docker 映像,并删除所有映像,仅保存最新的。 例子。
TestImage:v1
TestImage:v2
TestImage:v3
TestImage:v4
该命令将删除所有名为“TestImage”的图像,但保存 TestImage:v4(按日期最新)。
实际的命令。
Server storing multiple docker images with same name but with different tags, I am finding the good command which will search docker images with same name, but with different tags, and delete all, saving only the newest.
Example.
TestImage:v1
TestImage:v2
TestImage:v3
TestImage:v4
The command will delete all images which have name "TestImage" but save TestImage:v4 (which is newest by date).
The actual command .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您安装了Docker CLI,以下内容应有效:
第一个命令将所有本地图像带有给定名称。使用
-Q
标志意味着仅输出图像ID。然后,
tail
程序跳过了这些ID中的第一个(换句话说,在第2行开始读取)。由于图像是从旧到旧的,这意味着要跳过最新的图像。然后,
XARGS
将所有输出的ID带入同一行,以便Docker
可以轻松解释它们。在此步骤中获得的ID可能看起来像这样:
Docker Image RM
将使用这些ID删除所有图像。Provided you have the docker cli installed, the following should work:
The first command loads all local images with the given name. Using the
-q
flag means that only the image ids are being outputted.the
tail
program then skips the first one of these ids (in other words, starts reading at line 2). Since images are sorted from new to old, this means the newest image is skipped.The
xargs
then brings all the outputted ids into the same line, so thatdocker
can interpret them easily.The ids obtained in that step may look something like this:
docker image rm
will then remove all images with these ids.