2

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?

Pixie
  • 29
  • 2
  • In [What is, and what use cases have the dot "." in helm charts?](https://stackoverflow.com/questions/62472224/what-is-and-what-use-cases-have-the-dot-in-helm-charts) I've written a very complete answer to essentially this (about a different Kubernetes-related tool also using the Go `text/template` engine) but that may be more detail than you need. – David Maze Mar 01 '23 at 12:09

1 Answers1

1

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:

Fcmam5
  • 4,888
  • 1
  • 16
  • 33
  • I have read all the documentation, but I still do not know what is the dot for. Why do I need to put a dot instead of just put mounted? – Pixie Mar 01 '23 at 14:51
  • It is a syntax, as their documentation mentioned: `Execution of the template walks the structure and sets the cursor, represented by a period '.' and called "dot", to the value at the current location in the structure as execution proceeds.` so basically the dot is a cursor, you have it in the beginning means that `Mount` key is on your top level – Fcmam5 Mar 01 '23 at 15:53
  • It is not like JavaScript's deconstructuring, it's just a different syntax – Fcmam5 Mar 01 '23 at 15:53