...

Text file src/github.com/docker/cli/docs/reference/commandline/network_ls.md

Documentation: github.com/docker/cli/docs/reference/commandline

     1# network ls
     2
     3<!---MARKER_GEN_START-->
     4List networks
     5
     6### Aliases
     7
     8`docker network ls`, `docker network list`
     9
    10### Options
    11
    12| Name                                   | Type     | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                          |
    13|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
    14| [`-f`](#filter), [`--filter`](#filter) | `filter` |         | Provide filter values (e.g. `driver=bridge`)                                                                                                                                                                                                                                                                                                                                                                                         |
    15| [`--format`](#format)                  | `string` |         | Format output using a custom template:<br>'table':            Print output in table format with column headers (default)<br>'table TEMPLATE':   Print output in table format using the given Go template<br>'json':             Print in JSON format<br>'TEMPLATE':         Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
    16| `--no-trunc`                           |          |         | Do not truncate the output                                                                                                                                                                                                                                                                                                                                                                                                           |
    17| `-q`, `--quiet`                        |          |         | Only display network IDs                                                                                                                                                                                                                                                                                                                                                                                                             |
    18
    19
    20<!---MARKER_GEN_END-->
    21
    22## Description
    23
    24Lists all the networks the Engine `daemon` knows about. This includes the
    25networks that span across multiple hosts in a cluster.
    26
    27## Examples
    28
    29### List all networks
    30
    31```console
    32$ docker network ls
    33NETWORK ID          NAME                DRIVER          SCOPE
    347fca4eb8c647        bridge              bridge          local
    359f904ee27bf5        none                null            local
    36cf03ee007fb4        host                host            local
    3778b03ee04fc4        multi-host          overlay         swarm
    38```
    39
    40Use the `--no-trunc` option to display the full network id:
    41
    42```console
    43$ docker network ls --no-trunc
    44NETWORK ID                                                         NAME                DRIVER           SCOPE
    4518a2866682b85619a026c81b98a5e375bd33e1b0936a26cc497c283d27bae9b3   none                null             local
    46c288470c46f6c8949c5f7e5099b5b7947b07eabe8d9a27d79a9cbf111adcbf47   host                host             local
    477b369448dccbf865d397c8d2be0cda7cf7edc6b0945f77d2529912ae917a0185   bridge              bridge           local
    4895e74588f40db048e86320c6526440c504650a1ff3e9f7d60a497c4d2163e5bd   foo                 bridge           local
    4963d1ff1f77b07ca51070a8c227e962238358bd310bde1529cf62e6c307ade161   dev                 bridge           local
    50```
    51
    52### <a name="filter"></a> Filtering (--filter)
    53
    54The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there
    55is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`).
    56Multiple filter flags are combined as an `OR` filter. For example,
    57`-f type=custom -f type=builtin` returns both `custom` and `builtin` networks.
    58
    59The currently supported filters are:
    60
    61* driver
    62* id (network's id)
    63* label (`label=<key>` or `label=<key>=<value>`)
    64* name (network's name)
    65* scope (`swarm|global|local`)
    66* type (`custom|builtin`)
    67
    68#### Driver
    69
    70The `driver` filter matches networks based on their driver.
    71
    72The following example matches networks with the `bridge` driver:
    73
    74```console
    75$ docker network ls --filter driver=bridge
    76NETWORK ID          NAME                DRIVER            SCOPE
    77db9db329f835        test1               bridge            local
    78f6e212da9dfd        test2               bridge            local
    79```
    80
    81#### ID
    82
    83The `id` filter matches on all or part of a network's ID.
    84
    85The following filter matches all networks with an ID containing the
    86`63d1ff1f77b0...` string.
    87
    88```console
    89$ docker network ls --filter id=63d1ff1f77b07ca51070a8c227e962238358bd310bde1529cf62e6c307ade161
    90NETWORK ID          NAME                DRIVER           SCOPE
    9163d1ff1f77b0        dev                 bridge           local
    92```
    93
    94You can also filter for a substring in an ID as this shows:
    95
    96```console
    97$ docker network ls --filter id=95e74588f40d
    98NETWORK ID          NAME                DRIVER          SCOPE
    9995e74588f40d        foo                 bridge          local
   100
   101$ docker network ls --filter id=95e
   102NETWORK ID          NAME                DRIVER          SCOPE
   10395e74588f40d        foo                 bridge          local
   104```
   105
   106#### Label
   107
   108The `label` filter matches networks based on the presence of a `label` alone or a `label` and a
   109value.
   110
   111The following filter matches networks with the `usage` label regardless of its value.
   112
   113```console
   114$ docker network ls -f "label=usage"
   115NETWORK ID          NAME                DRIVER         SCOPE
   116db9db329f835        test1               bridge         local
   117f6e212da9dfd        test2               bridge         local
   118```
   119
   120The following filter matches networks with the `usage` label with the `prod` value.
   121
   122```console
   123$ docker network ls -f "label=usage=prod"
   124NETWORK ID          NAME                DRIVER        SCOPE
   125f6e212da9dfd        test2               bridge        local
   126```
   127
   128#### Name
   129
   130The `name` filter matches on all or part of a network's name.
   131
   132The following filter matches all networks with a name containing the `foobar` string.
   133
   134```console
   135$ docker network ls --filter name=foobar
   136NETWORK ID          NAME                DRIVER       SCOPE
   13706e7eef0a170        foobar              bridge       local
   138```
   139
   140You can also filter for a substring in a name as this shows:
   141
   142```console
   143$ docker network ls --filter name=foo
   144NETWORK ID          NAME                DRIVER       SCOPE
   14595e74588f40d        foo                 bridge       local
   14606e7eef0a170        foobar              bridge       local
   147```
   148
   149#### Scope
   150
   151The `scope` filter matches networks based on their scope.
   152
   153The following example matches networks with the `swarm` scope:
   154
   155```console
   156$ docker network ls --filter scope=swarm
   157NETWORK ID          NAME                DRIVER              SCOPE
   158xbtm0v4f1lfh        ingress             overlay             swarm
   159ic6r88twuu92        swarmnet            overlay             swarm
   160```
   161
   162The following example matches networks with the `local` scope:
   163
   164```console
   165$ docker network ls --filter scope=local
   166NETWORK ID          NAME                DRIVER              SCOPE
   167e85227439ac7        bridge              bridge              local
   1680ca0e19443ed        host                host                local
   169ca13cc149a36        localnet            bridge              local
   170f9e115d2de35        none                null                local
   171```
   172
   173#### Type
   174
   175The `type` filter supports two values; `builtin` displays predefined networks
   176(`bridge`, `none`, `host`), whereas `custom` displays user defined networks.
   177
   178The following filter matches all user defined networks:
   179
   180```console
   181$ docker network ls --filter type=custom
   182NETWORK ID          NAME                DRIVER       SCOPE
   18395e74588f40d        foo                 bridge       local
   18463d1ff1f77b0        dev                 bridge       local
   185```
   186
   187By having this flag it allows for batch cleanup. For example, use this filter
   188to delete all user defined networks:
   189
   190```console
   191$ docker network rm `docker network ls --filter type=custom -q`
   192```
   193
   194A warning will be issued when trying to remove a network that has containers
   195attached.
   196
   197### <a name="format"></a> Format the output (--format)
   198
   199The formatting options (`--format`) pretty-prints networks output
   200using a Go template.
   201
   202Valid placeholders for the Go template are listed below:
   203
   204| Placeholder  | Description                                                                            |
   205|--------------|----------------------------------------------------------------------------------------|
   206| `.ID`        | Network ID                                                                             |
   207| `.Name`      | Network name                                                                           |
   208| `.Driver`    | Network driver                                                                         |
   209| `.Scope`     | Network scope (local, global)                                                          |
   210| `.IPv6`      | Whether IPv6 is enabled on the network or not.                                         |
   211| `.Internal`  | Whether the network is internal or not.                                                |
   212| `.Labels`    | All labels assigned to the network.                                                    |
   213| `.Label`     | Value of a specific label for this network. For example `{{.Label "project.version"}}` |
   214| `.CreatedAt` | Time when the network was created                                                      |
   215
   216When using the `--format` option, the `network ls` command will either
   217output the data exactly as the template declares or, when using the
   218`table` directive, includes column headers as well.
   219
   220The following example uses a template without headers and outputs the
   221`ID` and `Driver` entries separated by a colon (`:`) for all networks:
   222
   223```console
   224$ docker network ls --format "{{.ID}}: {{.Driver}}"
   225afaaab448eb2: bridge
   226d1584f8dc718: host
   227391df270dc66: null
   228```
   229
   230To list all networks in JSON format, use the `json` directive:
   231
   232```console
   233$ docker network ls --format json
   234{"CreatedAt":"2021-03-09 21:41:29.798999529 +0000 UTC","Driver":"bridge","ID":"f33ba176dd8e","IPv6":"false","Internal":"false","Labels":"","Name":"bridge","Scope":"local"}
   235{"CreatedAt":"2021-03-09 21:41:29.772806592 +0000 UTC","Driver":"host","ID":"caf47bb3ac70","IPv6":"false","Internal":"false","Labels":"","Name":"host","Scope":"local"}
   236{"CreatedAt":"2021-03-09 21:41:29.752212603 +0000 UTC","Driver":"null","ID":"9d096c122066","IPv6":"false","Internal":"false","Labels":"","Name":"none","Scope":"local"}
   237```
   238
   239## Related commands
   240
   241* [network disconnect ](network_disconnect.md)
   242* [network connect](network_connect.md)
   243* [network create](network_create.md)
   244* [network inspect](network_inspect.md)
   245* [network rm](network_rm.md)
   246* [network prune](network_prune.md)
   247* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/)

View as plain text