diff --git a/docs/reference/commandline/history.md b/docs/reference/commandline/history.md index b68cc8695d..cfc52f83b7 100644 --- a/docs/reference/commandline/history.md +++ b/docs/reference/commandline/history.md @@ -21,10 +21,11 @@ Usage: docker history [OPTIONS] IMAGE Show the history of an image Options: - --help Print usage - -H, --human Print sizes and dates in human readable format (default true) - --no-trunc Don't truncate output - -q, --quiet Only show numeric IDs + --format string Pretty-print images using a Go template + --help Print usage + -H, --human Print sizes and dates in human readable format (default true) + --no-trunc Don't truncate output + -q, --quiet Only show numeric IDs ``` @@ -54,3 +55,42 @@ IMAGE CREATED CREATED BY c69cab00d6ef 5 months ago /bin/sh -c #(nop) MAINTAINER Lokesh Mandvekar 0 B 511136ea3c5a 19 months ago 0 B Imported from - ``` + +### Format the output + +The formatting option (`--format`) will pretty print history output +using a Go template. + +Valid placeholders for the Go template are listed below: + +| Placeholder | Description| +| ---- | ---- | +| `.ID` | Image ID | +| `.CreatedSince` | Elapsed time since the image was created if --human=true, otherwise timestamp of when image was created | +| `.CreatedAt` | Timestamp of when image was created | +| `.CreatedBy` | Command that was used to create the image | +| `.Size` | Image disk size | +| `.Comment` | Comment for image | + +When using the `--format` option, the `history` command will either +output the data exactly as the template declares or, when using the +`table` directive, will include column headers as well. + +The following example uses a template without headers and outputs the +`ID` and `CreatedSince` entries separated by a colon for all images: + +```bash +{% raw %} +$ docker images --format "{{.ID}}: {{.Created}} ago" + +cc1b61406712: 2 weeks ago +: 2 weeks ago +: 2 weeks ago +: 2 weeks ago +: 2 weeks ago +: 3 weeks ago +: 3 weeks ago +: 3 weeks ago + +{% endraw %} +``` \ No newline at end of file