在 “docker inspect” 中使用的点是用于什么的?

huangapple go评论52阅读模式
英文:

What is the dot used on docker inspect for?

问题

当你在一个Docker容器中调用JSON变量时,你想知道点号(.)的作用。

当你键入docker inspect -f '{{ .Mounts }}' $INSTANCE_ID时,你会看到存储在JSON中的挂载点,但该文件没有提到点号的含义。

点号的作用是什么?它代表什么意思?

英文:

I am calling to variables of the JSON on a docker container, and I want to know what is the dot (.) for.

When you type docker inspect -f '{{ .Mounts }}' $INSTANCE_ID you see the Mount points stored on the JSON, but the file do not mention nothing about dots.

What is the dot for? What does it mean?

答案1

得分: 1

根据文档

  • --format , -f 使用自定义模板格式化输出:‘json’:以JSON格式打印 ‘TEMPLATE’:使用给定的Go模板打印输出。
  • 有关使用模板格式化输出的更多信息,请参阅https://docs.docker.com/go/formatting/

并且:

Docker使用Go模板,您可以使用它们来操纵某些命令和日志驱动程序的输出格式。

所以基本上它是Go模板语法,允许您进行一些字符串操作,例如:

Mounts字段格式化为JSON:

docker inspect --format '{{json .Mounts}}' container

或者,例如:

Name转换为大写:

docker inspect --format "{{upper .Name}}" container

查看更多信息:

英文:

Accoding to the documentation:

> --format , -f Format output using a custom template: ‘json’: Print in JSON format ‘TEMPLATE’: Print output using the given Go template.
> Refer to https://docs.docker.com/go/formatting/ for more information
> about formatting output with templates

And:

> Docker uses Go templates which you can use to manipulate the output format of certain commands and log drivers.

So basically it's Go templates syntax that allows you to do some string manipulations, such as:

docker inspect --format '{{json .Mounts}}' container

To format Mounts field as JSON.

or, this for example:

docker inspect --format "{{upper .Name}}" container

Which transforms Name to uppercase.

See more:

huangapple
  • 本文由 发表于 2023年3月1日 08:42:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75598638.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定