我正在使用https://docs.docker.com/compose/compose-file/#extension-fields将相同的配置共享到多个容器。
我试图将一个元素添加到列表中而没有成功。
version: '3.4'
x-volumes:
&data
- .:/code
- ~/.ssh:/opt/data/home/developer/.ssh:ro
- ~/.bashrc:/opt/data/home/developer/.bashrc.d/bashrc.sh:ro
services:
nginx:
image: nginx
volumes:
<< : *data
- ./docker/conf/nginx_vhost.conf:/etc/nginx/conf.d/app.conf:ro
depends_on:
- fpm
我什至尝试过
version: '3.4'
x-volumes:
&data
- .:/code
- ~/.ssh:/opt/data/home/developer/.ssh:ro
- ~/.bashrc:/opt/data/home/developer/.bashrc.d/bashrc.sh:ro
services:
nginx:
image: nginx
volumes:
*data
- ./docker/conf/nginx_vhost.conf:/etc/nginx/conf.d/app.conf:ro
depends_on:
- fpm
但是每次我收到无效的YAML错误。
第一次尝试错误
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 13, column 7
expected <block end>, but found '-'
in "./docker-compose.yml", line 14, column 7
第二次尝试错误
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 11, column 5
expected <block end>, but found '<block sequence start>'
in "./docker-compose.yml", line 14, column 7
我尝试了一些Stackoverflow答案,但没有成功,例如https://stackoverflow.com/a/41728592/4487542
有可能吗?