I have the following broken docker-compose file
version: '3.4'
x-vols1: &vols-1
- /home/:/home/
x-vols2: &vols-2
- /tmp/:/tmp/
services:
app1:
container_name: app1
image: app1
volumes:
<<: *vols-1
app2:
container_name: app2
image: app2
volumes:
<<: *vols-1
<<: *vols-2
This fails with the following error
$ docker-compose -f test.yaml config
ERROR: yaml.constructor.ConstructorError: while constructing a mapping
in "./test.yaml", line 14, column 13
expected a mapping for merging, but found scalar
in "./test.yaml", line 4, column 7
Question 1: How can I merge arrays in docker-compose? The syntax that I am trying to use is the one for merging dicts
Question 2: If there is no way to merge arrays, is there a workaround?
Use case: I have multiple services, some of them map some volumes, others map other volumes, others map all volumes. I would like to not repeat myself.
Thank you!