Meaning of ampersand (&) in docker-compose.yml file

后端 未结 2 1264
鱼传尺愫
鱼传尺愫 2021-01-31 15:41

I recently came across this and was wondering what &django means

version: \'2\'

services:
  django: &django

I can\'t see

2条回答
  •  半阙折子戏
    2021-01-31 16:17

    These are a YAML feature called anchors, and are not particular to Docker Compose. I would suggest you have a look at below URL for more details

    https://learnxinyminutes.com/docs/yaml/

    Follow the section EXTRA YAML FEATURES

    YAML also has a handy feature called 'anchors', which let you easily duplicate content across your document. Both of these keys will have the same value:

    anchored_content: &anchor_name This string will appear as the value of two keys. other_anchor: *anchor_name

    Anchors can be used to duplicate/inherit properties

    base: &base
        name: Everyone has same name
    
    foo: &foo
        <<: *base
        age: 10
    
    bar: &bar
        <<: *base
        age: 20
    

提交回复
热议问题