I always forget which volumes belong to which stack. Counting on the volume name prefix works until two projects share a prefix. Compose can answer the question itself.
docker compose volumes
docker compose volumes web
docker compose volumes -q
The command prints the volumes of the project, and with a service name at the end only that service’s volumes. -q or --quiet prints only the names, which is useful in a script. The docs give no sample output, so I won’t show one here.
The --format option accepts table (the default), table TEMPLATE, json or a plain Go template. For example, --format json gives output that jq can read, and a template lets you pick only the columns you care about. The docs point to the general formatting page for the template syntax.
A use I’d have for it: before I run docker compose down -v, I list the volumes first to see what would go. Together with docker compose config you know both what the file declares and what exists.
The caveat is that it only covers one project. Like the other Compose commands it works on the project it finds from the current directory or from -p and -f, so run it from the project folder.
Further reading: docker compose volumes