此内容还未提供中文版,以下为英文版

Format command and log output

预计阅读时间: 1 分钟

Docker uses Go templates which allow users to manipulate the output format of certain commands and log drivers. Each command a driver provides has a detailed list of elements they support in their templates:

Template functions

Docker provides a set of basic functions to manipulate template elements. This is the complete list of the available functions with examples:

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

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 (join .Names "/") "/"}}' 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
format, formatting, output, templates, log