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?
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?
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.
You should try:
docker inspect <container> | grep "Volumes"
Glad it helped!
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>