使用命令删除旧的 docker 镜像后
docker images --no-trunc --format "{{.ID}} {{.CreatedSince}}" | grep " months" | awk "{ print $1 }" | xargs --no-run-if-empty docker rmi || true
在响应中,除了远程图像之外,还会发出以下内容:
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 2
Error: No such image: months
Error: No such image: ago
Error: No such image: 4
Error: No such image: months
Error: No such image: ago
Error: No such image: 4
Error: No such image: months
Error: No such image: ago
Error: No such image: 4
Error: No such image: months
Error: No such image: ago
Error: No such image: 4
Error: No such image: months
Error: No such image: ago
Error: No such image: 4
Error: No such image: months
Error: No such image: ago
依此类推。你能告诉我为什么他试图找到这些名字的图像,我怎样才能摆脱这个?
因为 awk 的双引号结构为您提供了完整的字符串
sha256:77b81ca0096a195cb0bf682cb126551e2bc8e0866b503a79bf6caf9364242502 9 days ago
因此,您可以删除图像并尝试删除不存在的图像:)
实际上,正如您已经猜到的那样,这种设计将正常工作