几个请求。
我想从docker images
获得json输出,我可以这样做
$ docker images --format "{{json . }}" |jq .
{
"Containers": "N/A",
"CreatedAt": "2022-07-27 11:12:07 +1000 AEST",
"CreatedSince": "8 days ago",
"Digest": "<none>",
"ID": "b673851840e8",
"Repository": "python",
"SharedSize": "N/A",
"Size": "915MB",
"Tag": "3.9",
"UniqueSize": "N/A",
"VirtualSize": "914.7MB"
}
{
"Containers": "N/A",
"CreatedAt": "2022-07-19 07:00:15 +1000 AEST",
"CreatedSince": "2 weeks ago",
"Digest": "<none>",
"ID": "d7d3d98c851f",
"Repository": "alpine",
"SharedSize": "N/A",
"Size": "5.53MB",
"Tag": "latest",
"UniqueSize": "N/A",
"VirtualSize": "5.529MB"
}
然后我想得到带有标签和ID的iamge名称
$ docker images --format "{{json . }}" |jq -r "[.Repository,.Tag,.ID]|@csv"
"python","3.9","b673851840e8"
"alpine","latest","d7d3d98c851f"
所以我的问题是,我怎样才能得到输出
python:3.9 b673851840e8
alpine:latest d7d3d98c851f
(可选)第二个请求,如何过滤仅用*python*
输出图像的输出
发布于 2022-08-04 03:36:11
您不必使用jq
来过滤基于名称的图像,使用本机--format
标志本身
docker images --format "{{.Repository}}:{{.Tag}} {{.ID}}"
(或)筛选以python
开头的名称
docker images --filter=reference='python*' --format "{{.Repository}}:{{.Tag}} {{.ID}}"
使用jq
,将所需字段收集到数组中,并使用任何字符串连接运算符。您还可以使用join("\t")
代替@tsv
来保持对join
方法的一致使用。
jq -r '[([.Repository, .Tag] | join(":")), .ID] | @tsv'
https://stackoverflow.com/questions/73235207
复制