docker-compose volumes_from 使用示例 [英] docker-compose volumes_from usage example
问题描述
能否举例说明使用volumes_from
从容器A到容器B共享路径,以及共享完成后容器B如何访问该路径.
谢谢
如文档所述 卷如果你在版本3
你可以使用顶级卷
来定义一个命名卷为db-data
ee下面的代码,您可以在每个服务中引用它,如下所示:
版本:3"服务:网络:nginx:高山端口:- 80:80"邮局:图片:postgres:9.4卷:- 数据库数据:/var/lib/db备份:图片:postgres:9.4卷:- 数据库数据:/var/lib/backup/dataRedis:图片:redis端口:- 6379:6379"卷:- ./数据:/数据卷:数据库数据:
<块引用>
2.0 版:
volumes_from
允许您从另一个服务或容器挂载所有数据或卷,您必须指定访问级别如何文档说 volumes from 在您的代码中,您可以使用以下内容:
版本:2"服务:网络:图片:nginx:高山端口:- 80:80"卷来自:- Redis:rw邮局:图片:postgres:9.4卷:-/数据/网络应用程序备份:图片:postgres:9.4卷:-/var/lib/backup/dataRedis:图片:redis端口:- 6379:6379"卷:-/数据/数据库
上面的代码 redis
定义一个卷服务,然后你可以在另一个容器中使用例如 web
和 volumes_from
看起来像 web 服务使用该卷服务指定读写
Can you please provide an example to sharing a path using volumes_from
from container A to Container B, in addition how container B can access this path after sharing is done.
Thanks
As documentation said volumes if you are in version 3
you can use The top-level volumes
to define a named volume as db-data
ee code below and you can reference it in every services something like this:
version: "3"
services:
web:
nginx:alpine
ports:
- "80:80"
postgres:
image: postgres:9.4
volumes:
- db-data:/var/lib/db
backup:
image: postgres:9.4
volumes:
- db-data:/var/lib/backup/data
redis:
image: redis
ports:
- "6379:6379"
volumes:
- ./data:/data
volumes:
db-data:
version 2.0:
volumes_from
allow you mount all data or volume from another service or container, you have to specify the access level how documentation said volumes from in your code you can use something like this:
version: "2"
services:
web:
image: nginx:alpine
ports:
- "80:80"
volumes_from:
- redis:rw
postgres:
image: postgres:9.4
volumes:
- /data/webapp
backup:
image: postgres:9.4
volumes:
- /var/lib/backup/data
redis:
image: redis
ports:
- "6379:6379"
volumes:
- /data/db
To code above redis
define a volume services and then you can use in another container for example web
with volumes_from
look like web service use that volume service specify access level to read and write
这篇关于docker-compose volumes_from 使用示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!