我正在尝试使用docker ps和json格式命令生成看起来像这样的输出
{"Names":"name"}
docker ps --format '{{json .Names}}'
没有标签的输出{"name"}
。
[docker ps --format '{{json .}}'
提供所有带有标签的容器信息,但我什么都不想要。
最好基于下面的所有占位符名称,我希望有一个如下所示的输出,其中包含以我选择的顺序选择的字段:
{"ID":"Container ID", "Image":"Image ID", "Names":"name"}
Placeholder Description
.ID Container ID
.Image Image ID
.Command Quoted command
.CreatedAt Time when the container was created.
.RunningFor Elapsed time since the container was started.
.Ports Exposed ports.
.Status Container status.
.Size Container disk size.
.Names Container names.
.Labels All labels assigned to the container.
.Label Value of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}'
.Mounts Names of the volumes mounted in this container.
.Networks Names of the networks attached to this container.
您可以使用以下格式:
docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}'
它输出:
{"ID":"ed3c992b7472", "Image": "alpine:3.9", "Names":"wizardly_buck"}