On my machine I have a few volumes whose names look like hashes. I don't remember creating them or using them. docker volume inspect
shows that they were created far back in the past. Is there any way to check when they were last used, or what they were used by?
The only real way to find out which volumes are in use by what - that I know - is to enumerate all the containers on your system, then for each container, extract the list of volumes it references:
docker container inspect $(container) --format '{{range .Mounts}}{{.Name}}{{end}}'
To achieve your actual objective, Docker automatically protects volumes from removal if they are referenced by containers and the volume prune can do this cleanup for you:
docker volume prune