5

How can I list all the volumes of a Docker container? I understand that it should be easy to get but I cannot find how.

Also, is it possible to get the volumes of deleted containers and remove them?

starikovs
  • 3,240
  • 4
  • 28
  • 33
  • 1
    Did you try: docker inspect | grep "Volumes"? – jbarrueta May 14 '15 at 08:12
  • @jbarrueta good idea but it doen't work correctly I just get json keys names.. :) But `docker inspect ` is what I needed. Thanks. – starikovs May 14 '15 at 08:33
  • Glad it helped @starikovs, since you already accepted the answer but it's the same as mine, I will add it as a response and maybe you can up voted. – jbarrueta May 14 '15 at 08:41
  • 1
    possible duplicate of [How do you list volumes baked into a docker image?](http://stackoverflow.com/questions/30133664/how-do-you-list-volumes-baked-into-a-docker-image) – L0j1k May 14 '15 at 16:42

5 Answers5

4

You can use docker ps, get container id and write:

$ docker inspect container_id

like here:

"Volumes": {
  ..
},
"VolumesRW": {
  ..
}

It would give you all volumes of container.

wsl
  • 8,875
  • 1
  • 20
  • 24
  • @starikovs that has changes with docker 1.8.1 (August 2015): see http://stackoverflow.com/a/31997267/6309 – VonC Aug 13 '15 at 20:15
3

Use this:

docker inspect --format='{{.HostConfig.Binds}}' <container id>
Yogesh_D
  • 17,656
  • 10
  • 41
  • 55
2

You should try:

docker inspect <container> | grep "Volumes"

Glad it helped!

jbarrueta
  • 4,907
  • 2
  • 20
  • 21
2

docker inspect provides all needed information. Using grep to filter the output is not a good thing to do. The --format option of docker inspect is way better in filtering the output.

For docker 1.12 and possibly earlier versions this lists all volumes:

docker inspect --format='{{range .Mounts}}{{.Destination}}  {{end}}' <containerid>

You can add all information from the inspect data that you like in your output and use the go template language to sculpt the output to your needs.

The following output will list all local volumes as in the first example and if it is not a local volume it also prints the source with it.

docker inspect --format='{{range .Mounts}}{{if eq .Driver "local"}}{{.Destination}} {{else}} {{.Source}}:{{.Destination}} {{end}} {{end}}' <cid>
itsafire
  • 5,607
  • 3
  • 37
  • 48
0

I prefer to see everything nicely formatted. With the help of jq, we can maintain the label of the data for the source and destination of the docker mount (volume). Define a bash function:

docvol () # reports the source and destination of the <container_id>'s mounts (volumes)
{
  docker inspect ${1} | jq '.[].Mounts[] | { src: .Source, dst: .Destination }'
}

Then we can use this bash function like so:

me@beastmode:~$ docvol 3d817a5f7a3d
{
  "src": "/home/me/ion/proj-grafana/federate.yml",
  "dst": "/etc/prometheus/federate.yml"
}
{
  "src": "/var/lib/docker/volumes/0472f8892378a40a9df769ed182c5361bc21/_data",
  "dst": "/prometheus"
}
activedecay
  • 10,129
  • 5
  • 47
  • 71