Docker Community Forums

Share and learn in the Docker community.

YML : need some help


(Anacondaonline) #1

In a YMLfile I see this
docker-type


(Anacondaonline) #2

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.


(David Maze) #3

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

(Anacondaonline) #4

what is the equivalent json to this?


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

(Anacondaonline) #6

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


(David Maze) #7

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.