Reputation: 3398
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?
Upvotes: 5
Views: 7163
Reputation: 10877
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"
}
Upvotes: 1
Reputation: 6103
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>
Upvotes: 2
Reputation: 18809
Use this:
docker inspect --format='{{.HostConfig.Binds}}' <container id>
Upvotes: 3
Reputation: 5185
You should try:
docker inspect <container> | grep "Volumes"
Glad it helped!
Upvotes: 2
Reputation: 10325
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.
Upvotes: 4