Docker如何获取容器使用的卷 [英] Docker how to get volumes used by a container

查看:143
本文介绍了Docker如何获取容器使用的卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Docker 1.10版。如何获取容器使用的卷?

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

我也知道卷API可用,所以我也可以这样做:

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

docker volume ls

docker volume inspect $volumeID

但我找不到它们之间的任何链接信息。我应该使用什么?

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

推荐答案

您可以通过

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

如果我创建一个名为 volumehello的卷,并启动一个使用 volumehello的名为 hello的容器:

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

然后我们可以通过运行以下命令获取 hello容器的体积信息:

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

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

我们将得到:

[{volumehello /var/lib/docker/volumes/volumehello/_data /tmp/data local z true rprivate}]




  • volumehello 是卷名

  • / var / lib / docker / volumes / volumehello / _data 是主机位置卷的状态

  • / tmp / data 是容器中卷的映射位置

    • 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
    • 这篇关于Docker如何获取容器使用的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆