Filter commands (original) (raw)
You can use the --filter
flag to scope your commands. When filtering, the commands only include entries that match the pattern you specify.
The --filter
flag expects a key-value pair separated by an operator.
The key represents the field that you want to filter on. The value is the pattern that the specified field must match. The operator can be either equals (=
) or not equals (!=
).
For example, the command docker images --filter reference=alpine
filters the output of the docker images
command to only print alpine
images.
The available fields (reference
in this case) depend on the command you run. Some filters expect an exact match. Others handle partial matches. Some filters let you use regular expressions.
Refer to theCLI reference description for each command to learn about the supported filtering capabilities for each command.
You can combine multiple filters by passing multiple --filter
flags. The following example shows how to print all images that match alpine:latest
orbusybox
- a logical OR
.
Multiple negated filters
Some commands support negated filters onlabels. Negated filters only consider results that don't match the specified patterns. The following command prunes all containers that aren't labeled foo
.
There's a catch in combining multiple negated label filters. Multiple negated filters create a single negative constraint - a logical AND
. The following command prunes all containers except those labeled both foo
and bar
. Containers labeled either foo
or bar
, but not both, will be pruned.
For more information about filtering commands, refer to the CLI reference description for commands that support the --filter
flag:
- docker config ls
- docker container prune
- docker image prune
- docker image ls
- docker network ls
- docker network prune
- docker node ls
- docker node ps
- docker plugin ls
- docker container ls
- docker search
- docker secret ls
- docker service ls
- docker service ps
- docker stack ps
- docker system prune
- docker volume ls
- docker volume prune