[英]Meaning of ampersand (&) in docker-compose.yml file
这些是称为锚点的YAML功能,并不特定于Docker Compose。 我建议您查看以下URL以获取更多详细信息
https://learnxinyminutes.com/docs/yaml/
请遵循EXTRA YAML FEATURES
部分
YAML还有一个名为“锚点”的便捷功能,可让您轻松复制文档中的内容。 这两个键都具有相同的值:
anchored_content : &anchor_name此字符串将显示为两个键的值。 other_anchor: * anchor_name
base: &base
name: Everyone has same name
foo: &foo
<<: *base
age: 10
bar: &bar
<<: *base
age: 20
为了补充Tarun的答案, &
识别一个锚点, *
是一个别名,用于回顾锚点。 它在YAML规范中描述如下:
在表示图中,节点可以出现在多个集合中。 序列化此类数据时,第一次出现的节点由锚标识。 每个后续事件都被序列化为别名节点,该节点返回此锚点。
边注:
对于那些想要在docker-compose文件中开始使用锚点的人来说,有更强大的方法可以通过使用docker-compose YAML扩展字段来制作可重用的锚点。
version: "3.4"
# x-docker-data is an extension and when docker-compose
# parses the YAML, it will not do anything with it
x-docker-data: &docker-file-info
build:
context: .
dockerfile: Dockerfile
services:
some_service_a:
<<: *docker-file-info
restart: on-failure
ports:
- 8080:9090
some_service_b:
<<: *docker-file-info
restart: on-failure
ports:
- 8080:9595
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.