chore: tier 1 freshness: content/config/formatting.md

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2023-10-26 22:05:15 +02:00
parent 657b3479ef
commit 0ebfc4ff7c
1 changed files with 8 additions and 31 deletions

View File

@ -6,8 +6,8 @@ aliases:
- /engine/admin/formatting/ - /engine/admin/formatting/
--- ---
Docker uses [Go templates](https://golang.org/pkg/text/template/) which you can Docker supports [Go templates](https://golang.org/pkg/text/template/) which you
use to manipulate the output format of certain commands and log drivers. can use to manipulate the output format of certain commands and log drivers.
Docker provides a set of basic functions to manipulate template elements. Docker provides a set of basic functions to manipulate template elements.
All of these examples use the `docker inspect` command, but many other CLI All of these examples use the `docker inspect` command, but many other CLI
@ -17,23 +17,19 @@ include examples of customizing the output format.
> **Note** > **Note**
> >
> When using the `--format` flag, you need observe your shell environment. > When using the `--format` flag, you need observe your shell environment.
> In a Posix shell, you can run the following with a single quote: > In a POSIX shell, you can run the following with a single quote:
>
> >
> ```console > ```console
> $ docker inspect --format '{{join .Args " , "}}' > $ docker inspect --format '{{join .Args " , "}}'
> ``` > ```
> >
>
> Otherwise, in a Windows shell (for example, PowerShell), you need to use single quotes, but > Otherwise, in a Windows shell (for example, PowerShell), you need to use single quotes, but
> escape the double quotes inside the params as follows: > escape the double quotes inside the parameters as follows:
>
> >
> ```console > ```console
> $ docker inspect --format '{{join .Args \" , \"}}' > $ docker inspect --format '{{join .Args \" , \"}}'
> ``` > ```
> >
>
{ .important } { .important }
## join ## join
@ -41,89 +37,70 @@ include examples of customizing the output format.
`join` concatenates a list of strings to create a single string. `join` concatenates a list of strings to create a single string.
It puts a separator between each element in the list. It puts a separator between each element in the list.
```console ```console
$ docker inspect --format '{{join .Args " , "}}' container $ docker inspect --format '{{join .Args " , "}}' container
``` ```
## table ## table
`table` specifies which fields you want to see its output. `table` specifies which fields you want to see its output.
```console ```console
$ docker image list --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}" $ docker image list --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"
``` ```
## json ## json
`json` encodes an element as a json string. `json` encodes an element as a json string.
```console ```console
$ docker inspect --format '{{json .Mounts}}' container $ docker inspect --format '{{json .Mounts}}' container
``` ```
## lower ## lower
`lower` transforms a string into its lowercase representation. `lower` transforms a string into its lowercase representation.
```console ```console
$ docker inspect --format "{{lower .Name}}" container $ docker inspect --format "{{lower .Name}}" container
``` ```
## split ## split
`split` slices a string into a list of strings separated by a separator. `split` slices a string into a list of strings separated by a separator.
```console ```console
$ docker inspect --format '{{split .Image ":"}}' container $ docker inspect --format '{{split .Image ":"}}' container
``` ```
## title ## title
`title` capitalizes the first character of a string. `title` capitalizes the first character of a string.
```console ```console
$ docker inspect --format "{{title .Name}}" container $ docker inspect --format "{{title .Name}}" container
``` ```
## upper ## upper
`upper` transforms a string into its uppercase representation. `upper` transforms a string into its uppercase representation.
```console ```console
$ docker inspect --format "{{upper .Name}}" container $ docker inspect --format "{{upper .Name}}" container
``` ```
## println ## println
`println` prints each value on a new line. `println` prints each value on a new line.
```console ```console
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' container $ docker inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' container
``` ```
# Hint # Hint
To find out what data can be printed, show all content as json: To find out what data can be printed, show all content as json:
```console ```console
$ docker container ls --format='{{json .}}' $ docker container ls --format='{{json .}}'
``` ```