docker-compose volume_from使用示例 [英] docker-compose volumes_from usage example
问题描述
请提供一个示例,使用 volumes_from
从容器A到容器B共享路径,此外容器B在共享完成后如何访问该路径。 / p>
谢谢
如文档所述卷(如果您使用的是版本3
) 顶级卷
将命名卷定义为下面的 db-data
ee代码,您可以在每个服务是这样的:
版本: 3
服务:
网站:
nginx:alpine
端口:
- 80:80
postgres:
图片:postgres:9.4
卷:
-数据库数据:/ var / lib / db
备份:
映像:postgres:9.4
卷:
-数据库数据:/ var / lib / backup / data
redis:
图片:redis
端口:
- 6379:6379
卷:
-./data:/data
卷:
db-data:
版本2.0:
volumes_from
允许您从另一个服务或容器装载所有数据或卷,您必须指定访问级别,文档说明的方式来自的卷,您可以在代码中使用以下内容:
版本: 2
服务:
网站:
图片:nginx:alpine
端口:
- 80:80
volume_from:
-redis:rw
postgres:
图片:postgres:9.4
量:
- / data / webapp
备份:
映像:postgres:9.4
卷:
-/ var / lib / backup / data
redis:
图片:redis
端口:
- 6379:6379
数量:
-/ data / db
要对 redis
以上的代码进行定义批量服务,然后可以在另一个容器中使用,例如 web
和 volumes_from
访问级别为读写
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 volume_from使用示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!