12

I can list all containers with docker ps (-a), I can list all volumes with docker volumes ls, when I inspect a volume, I can see the name, driver and mountpoint, but not the container(s) it is being used by.

When I use docker inspect <container>, I can see the Mount data like this for example:

"Mounts": [
    {
        "Name": "centos_db_symfony",
        "Source": "/var/lib/docker/volumes/centos_db_symfony/_data",
        "Destination": "/var/lib/mysql",
        "Driver": "local",
        "Mode": "rw",
        "RW": true,
        "Propagation": "rprivate"
    },

so in theory, I could write a script that loops through all containers to match a specific volume by name. But I ran some containers through docker-compose, and didn't bind a name (like now is possible in v2) to some volumes, so they show up like a sha256 in the docker volume ls list, like this:

DRIVER              VOLUME NAME
local               34009871ded5936bae81197247746b708c3ec9e9b9832b702c09736a90...etc
local               centos_data
local               centos_db_symfony

In this case 34009871ded5 (example) was created before I named the volume in docker-compose and centos_db_symfony after.

Question

When docker-compose.yml volume information is updated like in this case making the volume named and the information in docker inspect <container> is updated, is the history forever lost or can I find out which container a volume was used by? If so, is it also possible to restore an old volume like this?

Extra info

docker-compose version 1.6.0, build d99cad6
Docker version 1.10.2, build c3959b1

1 Answer 1

17

As of Docker v1.11 you can filter ps by volumes! Unfortunately this is not available in previous versions.

Here's how it would be used:

docker ps -f "volume=/var/lib/mysql" 

or

docker ps -f "volume=centos_db_symfony"
3
  • 3
    I believe this feature was added in Docker 1.11, so the OP will need to upgrade to get it.
    – jwodder
    Jun 16, 2016 at 14:21
  • This helps if you know the volume name and want to track down containers, but not so helpful if you know the container and want to track down the volumes. Jul 25 at 22:31
  • if you no the container you can use "docker inspect" command and find the volume used by the container Jul 26 at 9:23

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.