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.
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?
docker-compose version 1.6.0, build d99cad6
Docker version 1.10.2, build c3959b1
docker volume ls --filter name=volume_name . To get volumes by container name, use docker inspect --format '{{ . Mounts }}' container_name or a variation of that: stackoverflow.com/questions/30133664/…
View a Data Volume You can use the docker volume ls command to view a list of data volumes. Use the docker volume inspect command to view the data volume details.
As of Docker v1.11 you can filter ps
by volume
s! 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With