Filter networks by scope and type
In this step, you will learn how to filter the list of Docker networks based on their scope and type. The scope
indicates where the network is available (e.g., local
or swarm
), and the type
refers to the network driver. While type
is often the same as driver
, using type
as a filter key is also possible.
You can use the --filter
option with the docker network ls
command to filter the output. To filter by scope, you use the key scope
. To filter by type, you use the key type
.
Let's filter the networks to show only those with a local
scope.
docker network ls --filter scope=local
The output will show all networks with the local
scope:
NETWORK ID NAME DRIVER SCOPE
b432a7b0f123 bridge bridge local
f567c8d1e234 host host local
a987b6c5d4e3 none null local
Now, let's filter the networks to show only those with a bridge
type.
docker network ls --filter type=bridge
The output will show networks with the bridge
type (which is the same as the bridge
driver in this case):
NETWORK ID NAME DRIVER SCOPE
b432a7b0f123 bridge bridge local
You can combine filters by using the --filter
option multiple times. For example, to filter for networks with local
scope and bridge
driver:
docker network ls --filter scope=local --filter driver=bridge
This will give you the same result as filtering by type=bridge in this specific environment, but it demonstrates how to combine filters.