cli icon indicating copy to clipboard operation
cli copied to clipboard

docs: improve documentation for "prune" commands specifying multiple (label) filters

Open thaJeztah opened this issue 9 months ago • 3 comments

Description

This got in through the docs.docker.com feedback form;

The line " If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")" unfortunately does NOT say if multiple filters are ANDed or ORed. For prune commands, this is very important, though.

It was reported for docker volume prune, but likely the same applies to other prune commands; https://docs.docker.com/reference/cli/docker/volume/prune/

https://github.com/docker/cli/blob/f9b3c8ce10c5f8bb0878959543b69c70c1344ed7/docs/reference/commandline/volume_prune.md?plain=1#L40-L52

We need to verify the behavior (behavior of some of the filter options haven't been documented well when combined with other filters, or same filter applied multiple times), and update the documentation accordingly to make it less ambiguous.

thaJeztah avatar Mar 06 '25 09:03 thaJeztah

Hi, we're a group of students at UT Austin looking to contribute to virtualization-related open-source projects for our class. We came across this issue and would like to work on it @thaJeztah , if you could assign this to us please.

Thanks so much!

mdhaduk avatar Apr 05 '25 17:04 mdhaduk

I want to work on improving this issue.

Antraxmin avatar Apr 29 '25 01:04 Antraxmin

Hey @thaJeztah I did a few clean tests to confirm this behavior.

Steps to reproduce:

docker rm -f $(docker ps -aq)
docker volume prune -f

# create labeled named volumes
docker volume create --label team=dev --label project=alpha vol1
docker volume create --label team=ops --label project=alpha vol2
docker volume create --label team=dev --label project=beta vol3

# verify labels
docker volume ls --format "table {{.Name}}\t{{.Labels}}"

# try pruning
docker volume prune --filter "label=team=dev"
docker volume prune --filter "label=project=alpha"
docker volume prune --filter "label=team=dev" --filter "label=project=alpha"

Observed behavior:

All commands print “Total reclaimed space: 0B” — the labeled volumes remain untouched.

Expected behavior:

Volumes matching the label filters (e.g., team=dev, project=alpha) should be pruned.

It seems docker volume prune currently filters only anonymous volumes created by containers, not named ones created via docker volume create.

Is this behavior intentional, or should filters also apply to named volumes with matching labels?

2003Aditya avatar Nov 04 '25 05:11 2003Aditya