卷和 docker-compose
Volumes and docker-compose
我正在尝试创建一个包含 --volumes-from
指令的 docker-compose.yml 文件。有谁知道语法?
我在网上找了一段时间,看来 --volumes-from
命令只能作为 docker 命令使用。希望我是错的。
2016 年 2 月:
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 issue or this 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.
我正在尝试创建一个包含 --volumes-from
指令的 docker-compose.yml 文件。有谁知道语法?
我在网上找了一段时间,看来 --volumes-from
命令只能作为 docker 命令使用。希望我是错的。
2016 年 2 月:
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 issue or this 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 replacesvolumes_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 theweb
service, and a bind mount defined for a single service (first path underdb
service volumes).The
db
service also uses a named volume calleddbdata
(second path underdb
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.