Reputation: 14656
I'm trying to create a docker-compose.yml file that contains a --volumes-from
instruction. Does anyone know the syntax?
I have been looking online for some time now, and it appears that the --volumes-from
command is only available as a docker command. I hope I'm wrong.
Upvotes: 8
Views: 39256
Reputation: 1328232
Aug. 2022:
brandt points out in the comments to the updated docker-compose documentation.
Note August 2017: with 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.
Example:
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.
February 2016:
The docs/compose-file.md
mentions:
Mount all of the volumes from another service or container, optionally specifying read-only access(ro) or read-write(rw).
(If no access level is specified, then read-write will be used.)
volumes_from:
- service_name
- service_name:ro
- container:container_name
- container:container_name:rw
For instance (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
Upvotes: 13