With Docker Compose v1.6.0+, there now is a new/version 2 file syntax for the docker-compose.yml file. The changes include a separate top level key named volumes. This allows to "centralize" volume definitions in one place.
What I am trying to do is to name volumes in there and have a single volume reference multiple path on my local host disk. The following is an example, throwing an exception with a Traceback that ends with
AttributeError: 'list' object has no attribute 'items'
Example docker-compose.yml:
version: '2'
services:
db:
image: postgres
volumes:
- database:/var/lib/postgres/data
php:
image: php-fpm:5.6
volumes:
- phpconf:/etc/php/conf.d
namedvolume:
container_name: namedvolume
build: ./Docker/Testvolume
volumes:
- ./Docker/Testvolume/shareme
volumes:
database:
- ./Docker/Postgres/db:ro
- ./Docker/Postgres/ini
phpconf:
- ./Docker/PHP-FPM/conf
singledir: ./Docker/foo
completemap: ./Docker/bar:/etc/service/conf.d
- namedvolume:/etc/service/conf.d # < this was a separate attempt w/o the other keys
… ?
So far I read through all the Docker Compose docs master-branch Volume configuration reference, the Docker Compose docs Volume/Volume-Driver reference and looked through GitHub examples to find the correct syntax that is expected. It seems no one is already using that (GitHub) and the documentation is far from being complete (docker.com). I also tried to build a separate volume as service and reference it in volumes, but that does not work as well. Any idea on how to this syntax is supposed to look like?
$(docker volume ls |awk '{print $2}')you can use$(docker volume ls -q)Not only is this simpler, it doesn't print "VOLUME" on the first line. – Arthur Tacca Jan 11 '17 at 10:32volumes_fromis to inherit the list of volumes from another container. To use a named volume, you use the service-level syntax- NAME:DEST, and set the path in the top levelvolumeskey. What this example does (at the time of writing this) is make a standard volume in addition to a named volume, and the named volume is simply not used. – trevorj May 09 '17 at 05:22