如何通过 cli 从 'docker images' cmd 中 grep 并获取 docker image_id 而无需使用鼠标选择?

问题描述 投票:0回答:1
[banner@stapp03 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              26828d185a8f        5 seconds ago       125MB
ubuntu              latest              174c8c134b2a        3 weeks ago         77.8MB

有 2 个图像 - 我想在 cli 中输入命令并获取最新的图像 ID(第一行)并将其用于其他后续命令。 不能用鼠标点击选择图片id,怎么办?

docker image grep dockerfile
1个回答
0
投票

我们可以通过

docker
定义每个
--format <fmt-string>
命令的输出格式。详情请参阅相应
docs.docker.com
页面

如果我们想要所有图像的 id,我们可以运行

$ docker image ls --format {{.Id}}

如果我们只想要 ubuntu 映像的 ID,我们可以运行

$ docker image ls ubuntu --format {{.Id}}
© www.soinside.com 2019 - 2024. All rights reserved.