YML : need some help

In a YMLfile I see this
docker-type

I’m a docker beginner. I am confused with the above syntax .

I understand in this example

source is a property.
target is a property.

I am expecting type to be a property also !!. …But its shown as a list in this example with a “-” . why ? I could not got the idea.

I would have been happier if type is also a property like source and target.

Can anyone please help me to understand this concept . I’m stuck at this part.

type, source, and target are all properties of a single object; volumes contains a list of these objects. I could write equivalent JSON (which should be valid YAML too!):

"volumes": [
  {
    "type": "volume",
    "source": "/data/mysql",
    "target": "/var/lib/mysql"
  }
]

And if you wanted to bind-mount multiple volumes the YAML syntax would be:

volumes:
  - type: volume
    source: /data/mysql
    target: /var/lib/mysql
  - type: volume
    source: /data/mysql-init
    target: /docker-entrypoint-initdb.d

what is the equivalent json to this?

{
  "volumes": [
    {
      "type": "volume",
      "source": "/data/mysql",
      "target": "/var/lib/mysql"
    },
    {
      "type": "volume",
      "source": "/data/mysql-init",
      "target": "/docker-entrypoint-initdb.d"
    }
  ]
}

thats a nice json syntax … readable , clean and understandable.
can we write json notation YML ?

Actually, you can: all JSON is supposed to be valid YAML. There are a lot of layout options in between too. Probably overly cramped is

volumes:
- { type: volume, source: /data/mysql, target: /var/lib/mysql }
- { type: volume, source: /data/mysql-init, target: /docker-entrypoint-initdb.d }

but it’s valid and also IMHO pretty clear.