[go: up one dir, main page]

{ const container = $el; // The div with overflow const item = document.getElementById('sidebar-current-page') if (item) { const containerTop = container.scrollTop; const containerBottom = containerTop + container.clientHeight; const itemTop = item.offsetTop - container.offsetTop; const itemBottom = itemTop + item.offsetHeight; // Scroll only if the item is out of view if (itemBottom > containerBottom - 200) { container.scrollTop = itemTop - (container.clientHeight / 2 - item.offsetHeight / 2); } } })" class="bg-background-toc dark:bg-background-toc fixed top-0 z-40 hidden h-screen w-full flex-none overflow-x-hidden overflow-y-auto md:sticky md:top-16 md:z-auto md:block md:h-[calc(100vh-64px)] md:w-[320px]" :class="{ 'hidden': ! $store.showSidebar }">
Contact support

Format command and log output

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

Docker provides a set of basic functions to manipulate template elements. All of these examples use the docker inspect command, but many other CLI commands have a --format flag, and many of the CLI command references include examples of customizing the output format.

Note

When using the --format flag, you need to observe your shell environment. In a POSIX shell, you can run the following with a single quote:

$ docker inspect --format '{{join .Args " , "}}'

Otherwise, in a Windows shell (for example, PowerShell), you need to use single quotes, but escape the double quotes inside the parameters as follows:

$ docker inspect --format '{{join .Args \" , \"}}'

join

join concatenates a list of strings to create a single string. It puts a separator between each element in the list.

$ docker inspect --format '{{join .Args " , "}}' container

table

table specifies which fields you want to see its output.

$ docker image list --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"

json

json encodes an element as a json string.

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

lower

lower transforms a string into its lowercase representation.

$ docker inspect --format "{{lower .Name}}" container

split

split slices a string into a list of strings separated by a separator.

$ docker inspect --format '{{split .Image ":"}}' container

title

title capitalizes the first character of a string.

$ docker inspect --format "{{title .Name}}" container

upper

upper transforms a string into its uppercase representation.

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

pad

pad adds whitespace padding to a string. You can specify the number of spaces to add before and after the string.

$ docker image list --format '{{pad .Repository 5 10}}'

This example adds 5 spaces before the image repository name and 10 spaces after.

truncate

truncate shortens a string to a specified length. If the string is shorter than the specified length, it remains unchanged.

$ docker image list --format '{{truncate .Repository 15}}'

This example displays the image repository name, truncating it to the first 15 characters if it's longer.

println

println prints each value on a new line.

$ docker inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' container

Hint

To find out what data can be printed, show all content as json:

$ docker container ls --format='{{json .}}'