Administrator
发布于 2024-05-10 / 0 阅读
0
0

yaml anchor and reference

those are elements of the YAML file format, which is used here to provide a configuration file for configtxgen. The "&" sign mean anchor and "*" reference to the anchor, this is basically used to avoid duplication, for example:

这些是YAML文件格式的元素,这里使用YAML文件格式为 configtxgen 提供配置文件。“&”号表示锚,“*”号表示锚,这基本上是用来避免重复的,例如:

version: "3.9"

services:
  production-db: &database-definition
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
  MYSQL_ROOT_PASSWORD: somewordpress
  MYSQL_DATABASE: wordpress
  MYSQL_USER: wordpress
  MYSQL_PASSWORD: wordpress
      ...
  test-db: *database-definition

在该示例中, &database-definition*database-definition 别名所引用的锚。

version: "3.9"

services:
  production-db: &database-definition
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment: &environment-definition
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: production-password
 
  test-db:
    <<: *database-definition
    environment:
        <<: *environment-definition
        MYSQL_PASSWORD: test-password

<< 是一种特殊的覆盖语法,它有效地允许别名的各个值可以更新。

https://yaml-online-parser.appspot.com/


评论