Docker --格式化为json。多个占位符的特定占位符语法
Docker --format with json. Specific placeholder syntax for multiple placeholders
我正在尝试使用 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"}
我正在尝试使用 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"}