How to determine what containers use the docker volume?

gerichhome picture gerichhome · Mar 17, 2017 · Viewed 21.2k times · Source

Suppose I have a volume and I know its name or id.

I want to determine the list of containers (their names or ids) that use the volume.

What commands can I use to retrieve this information?

I thought it can be stored in the output of docker volume inspect <id> command but it gives me nothing useful other than the mount point ("/var/lib/docker/volumes/<id>").

Answer

jwodder picture jwodder · Mar 17, 2017

docker ps can filter by volume to show all of the containers that mount a given volume:

docker ps -a --filter volume=VOLUME_NAME_OR_MOUNT_POINT

Reference: https://docs.docker.com/engine/reference/commandline/ps/#filtering