Over the lifetime of a Docker host machine, it's likely that orphaned volumes and other detritus will accumulate over time. You might find yourself fumbling a configuration and orphaning a volume yourself. However we got here, we have a bunch of volumes and we need to know if any of them are important. In a perfect world, they'll have decent names.
Luckily, we have tools at our disposal to handle this. My thought process almost always starts with "Can I make a newline separated list of the things I care about?" If I can do that, I can start automating my troubleshooting.
This is human readable, and we could even do some slicing with `cut` or `awk`, but Docker gives us a flag that will take us exactly where we need to go: `--format`. Docker uses Go's `text/template` library to power this feature and individual flags (usually) [document](https://docs.docker.com/reference/cli/docker/volume/ls/#format) the template verbs available. Here, we want `Name`.
The next part is fairly straightforward. We loop over this list and ask Docker to create a temporary container based on alpine, with a single volume mounted at `/test/`.
```
#! /bin/bash
# Newline separated list of volume names
volumes=$(docker volume ls --format="{{.Name}}")
for volume in $volumes; do
# Help the user keep track of which volume they're exploring
echo "Mounting $volume in a temporary image."
docker run --rm -v $volume:/test/ -it alpine /bin/sh
done
```
Running this script should do something like this:
```
./cycle-volumes.sh
Mounting d35fce052fbce42b94b2f9b2957be0f77090fa006b1a192030eff07db3675af2 in a temporary image.