Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker how to get volumes used by a container

Tags:

docker

I'm using Docker version 1.10. How can I get the volumes used by a container?

I know I can get the containers by:

docker ps

And I can inspect them with:

docker inspect $containerID

I also know that the volume API is available, so I can also do:

docker volume ls

and

docker volume inspect $volumeID

But I can't find any link information between them. What should I use?

like image 419
bitgandtter Avatar asked Feb 09 '16 23:02

bitgandtter


People also ask

How can I see docker volumes?

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.

Which command displays a list of volumes created by docker?

docker volume ls | Docker Documentation.


1 Answers

You can get the detail volume information of a container by

docker inspect --format="{{.Mounts}}" $containerID

If I create a volume named "volumehello", and start a container named "hello" which use "volumehello":

docker volume create --name volumehello
docker run -it -d --name=hello -v volumehello:/tmp/data hello-world

Then we can get the volume information of "hello" container by running:

docker inspect --format="{{.Mounts}}" hello

We will get:

[{volumehello /var/lib/docker/volumes/volumehello/_data /tmp/data local z true rprivate}]
  • volumehello is the volume name
  • /var/lib/docker/volumes/volumehello/_data is the host location of the volume
  • /tmp/data is the mapped location of the volume within the container
like image 98
KiwenLau Avatar answered Oct 19 '22 16:10

KiwenLau