gpt4 book ai didi

docker - 卷和 docker-compose

转载 作者:行者123 更新时间:2023-12-01 14:38:32 25 4
gpt4 key购买 nike

我正在尝试创建一个 docker-compose.yml 文件,其中包含 --volumes-from操作说明。有人知道语法吗?

我在网上找了一段时间,似乎是--volumes-from命令仅可用作 docker 命令。我希望我是错的。

最佳答案

2016 年 2 月:
docs/compose-file.md 提到:

Mount all of the volumes from another service or container, optionally specifying read-only access(ro) or read-write(rw).


(如果未指定访问级别,则将使用读写。)
volumes_from:
- service_name
- service_name:ro
- container:container_name
- container:container_name:rw
例如( from this issuethis one )
version: "2"

services:
...
db:
image: mongo:3.0.8
volumes_from:
- dbdata
networks:
- back
links:
- dbdata

dbdata:
image: busybox
volumes:
- /data/db

注意 2017 年 8 月:与 docker-compose version 3, regarding volumes :

The top-level volumes key defines a named volume and references it from each service’s volumes list.
This replaces volumes_from in earlier versions of the Compose file format. See Use volumes and Volume Plugins for general information on volumes.


例子:
version: "3.2"
services:
web:
image: nginx:alpine
volumes:
- type: volume
source: mydata
target: /data
volume:
nocopy: true
- type: bind
source: ./static
target: /opt/app/static

db:
image: postgres:latest
volumes:
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
- "dbdata:/var/lib/postgresql/data"

volumes:
mydata:
dbdata:

This example shows a named volume (mydata) being used by the web service, and a bind mount defined for a single service (first path under db service volumes).

The db service also uses a named volume called dbdata (second path under db service volumes), but defines it using the old string format for mounting a named volume.

Named volumes must be listed under the top-level volumes key, as shown.

关于docker - 卷和 docker-compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35701130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com