add support for filtering by network ID

This adds support for filtering by network ID, to be
consistent with other filter options.

Note that only *full* matches are returned; this is
consistent with other filters (e.g. volume), that
also return full matches only.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 7c46ba02e694ae540866b29ebf0dab76e556cc13
Component: engine
This commit is contained in:
Sebastiaan van Stijn
2016-06-06 02:04:33 +02:00
parent 4e024e3e7d
commit 94abb34940
6 changed files with 65 additions and 19 deletions

View File

@ -62,7 +62,7 @@ The currently supported filters are:
* since (container's id or name) - filters containers created since given id or name
* isolation (default|process|hyperv) (Windows daemon only)
* volume (volume name or mount point) - filters containers that mount volumes.
* network (network name) - filters containers connected to the provided network name
* network (network id or name) - filters containers connected to the provided network
#### Label
@ -209,15 +209,33 @@ The `volume` filter shows only containers that mount a specific volume or have a
#### Network
The `network` filter shows only containers that has endpoints on the provided network name.
The `network` filter shows only containers that are connected to a network with
a given name or id.
$docker run -d --net=net1 --name=test1 ubuntu top
$docker run -d --net=net2 --name=test2 ubuntu top
The following filter matches all containers that are connected to a network
with a name containing `net1`.
$docker ps --filter network=net1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1
```bash
$ docker run -d --net=net1 --name=test1 ubuntu top
$ docker run -d --net=net2 --name=test2 ubuntu top
$ docker ps --filter network=net1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1
```
The network filter matches on both the network's name and id. The following
example shows all containers that are attached to the `net1` network, using
the network id as a filter;
```bash
$ docker network inspect --format "{{.ID}}" net1
8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
$ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1
```
## Formatting