How to list the contents of a named volume in docker 1.9+?

Docker 1.9 added named volumes, so I ...

docker volume create --name postgres-data docker volume ls 

and i get

 local postgres-data 

everything is fine so far ..

so how do i see what is in the named volume? Is there any way to connect to it on the host system. How can I for a mounted host directory?

+31
source share
5 answers
 docker run --rm -i -v=postgres-data:/tmp/myvolume busybox find /tmp/myvolume 

Explanation: Create a minimal container with tools for viewing volume files (busybox), set the named volume in the container directory ( v=postgres-data:/tmp/myvolume ), list the volume files ( find /tmp/myvolume ). Remove the container when the listing is done ( --rm ).

+55
source

you can run docker volume inspect postgres-data

and see Mountpoint result section

therefore, the source parameter will point to the host directory can be /var/lib/docker/volumes/[volume_name]/_data

+25
source

Here is one idea ...

 docker run -it --name admin -v postgres-data:/var/lib/postgresql/data ubuntu 

then in an interactive shell

 ls /var/lib/postgresql/data 

Best ideas are welcome!

+5
source

I use this handy feature to display the contents of my volumes:

 dvolume() { local volume volumes_to_list=${1:-$(docker volume ls --quiet)} for volume in $volumes_to_list; do sudo ls -lRa "$(docker volume inspect --format '{{ .Mountpoint }}' "$volume")" echo done } 

Note that you can call a function in two ways:

 $ dvolume # for each volume, list its content $ dvolume <volume> # list <volume> content 
+3
source

Probably pointless, but still:

 sudo ls -l $(docker volume inspect myvolumename | jq -r '.[0].Mountpoint') 

Check out the jq document page for details on how to install this.

0
source

Source: https://habr.com/ru/post/1240658/


All Articles