我有一个目录(可能是后面的卷),我想与所有交互式容器共享。我知道,本机 Docker 卷存储在/var/lib/docker/volumes
and docker run -v
似乎是最简单的方法,但我认为Data Volume Container
是一种更加标准化的方式。我不知道如何从目录或现有的另一个卷创建此卷容器。也许是方法不对?
创建和共享卷有两种方法: 1. 使用VOLUME
的指示Dockerfile
。 2 指定-v <volume_name>
容器运行时和稍后使用期间的选项--volumes-from=<container>
与需要共享数据的每个后续容器。这是后者的前任:
- 启动你的第一个容器
-v
,然后在共享卷的目录下添加一个测试文件。
docker run -it -v /test-volume --name=testimage1 ubuntu:14.04 /bin/bash
root@ca30f0f99401:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test-volume ===> test-volume dir got created here
root@ca30f0f99401:/# touch test-volume/1
root@ca30f0f99401:/# cat > test-volume/1
Test Message!
- 在主机操作系统中,您可以通过检查容器来获取卷的详细信息:
docker inspect ca30f0f99401 | grep -i --color -E '^|Vol'
"Mounts":
{
"Name": "025835b8b47d282ec5f27c53b3165aee83ecdb626dc36b3b18b2e128595d9134",
"Source": "/var/lib/docker/volumes/025835b8b47d282ec5f27c53b3165aee83ecdb626dc36b3b18b2e128595d9134/_data",
"Destination": "/test-volume",
"Driver": "local",
"Mode": "",
"RW": true
"Image": "ubuntu:14.04",
"Volumes": {
"/test-volume": {} }
- 启动另一个具有共享卷的容器并检查共享文件夹/文件是否存在。
$ docker run -it --name=testimage2 --volumes-from=testimage1 ubuntu:14.04 /bin/bash
root@60ff1dcebc44:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test-volume tmp usr var
root@60ff1dcebc44:/# cat test-volume/1
Test Message!
- 转到步骤 3 以与新容器共享卷。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)