diff --git a/docs/reference/commandline/network_ls.md b/docs/reference/commandline/network_ls.md index 49614bdaf4..e8ba6d97fb 100644 --- a/docs/reference/commandline/network_ls.md +++ b/docs/reference/commandline/network_ls.md @@ -20,6 +20,7 @@ Aliases: Options: -f, --filter value Provide filter values (i.e. 'dangling=true') (default []) + --format string Pretty-print networks using a Go template --help Print usage --no-trunc Do not truncate the output -q, --quiet Only display volume names @@ -169,6 +170,38 @@ $ docker network rm `docker network ls --filter type=custom -q` A warning will be issued when trying to remove a network that has containers attached. +## Formatting + +The formatting options (`--format`) pretty-prints networks output +using a Go template. + +Valid placeholders for the Go template are listed below: + +Placeholder | Description +------------|------------------------------------------------------------------------------------------ +`.ID` | Network ID +`.Name` | Network name +`.Driver` | Network driver +`.Scope` | Network scope (local, global) +`.IPv6` | Whether IPv6 is enabled on the network or not. +`.Internal` | Whether the network is internal or not. +`.Labels` | All labels assigned to the network. +`.Label` | Value of a specific label for this network. For example `{{.Label "project.version"}}` + +When using the `--format` option, the `network ls` command will either +output the data exactly as the template declares or, when using the +`table` directive, includes column headers as well. + +The following example uses a template without headers and outputs the +`ID` and `Driver` entries separated by a colon for all networks: + +```bash +$ docker network ls --format "{{.ID}}: {{.Driver}}" +afaaab448eb2: bridge +d1584f8dc718: host +391df270dc66: null +``` + ## Related information * [network disconnect ](network_disconnect.md) diff --git a/man/docker-network-ls.1.md b/man/docker-network-ls.1.md index 3eeff05993..d5399d7a59 100644 --- a/man/docker-network-ls.1.md +++ b/man/docker-network-ls.1.md @@ -7,6 +7,7 @@ docker-network-ls - list networks # SYNOPSIS **docker network ls** [**-f**|**--filter**[=*[]*]] +[**--format**=*"TEMPLATE"*] [**--no-trunc**[=*true*|*false*]] [**-q**|**--quiet**[=*true*|*false*]] [**--help**] @@ -162,6 +163,18 @@ attached. **-f**, **--filter**=*[]* filter output based on conditions provided. +**--format**="*TEMPLATE*" + Pretty-print networks using a Go template. + Valid placeholders: + .ID - Network ID + .Name - Network name + .Driver - Network driver + .Scope - Network scope (local, global) + .IPv6 - Whether IPv6 is enabled on the network or not + .Internal - Whether the network is internal or not + .Labels - All labels assigned to the network + .Label - Value of a specific label for this network. For example `{{.Label "project.version"}}` + **--no-trunc**=*true*|*false* Do not truncate the output