YAML Ain't Markup Language
The YAML acronym was shorthand for "Yet Another Markup Language". But the maintainers renamed it to "YAML Ain't Markup Language" to place more emphasis on its data-oriented features.
What is YAML: YAML is a data serialization language that is often used for writing configuration files. YAML has steadily increased in popularity over the last few years because it is human-readable and easy to understand.
YAML syntax in brief: YAML uses Python-style indentation to indicate nesting, and it has a set of key rules that should be followed to make a valid YAML file. In short,
- Indentation represents the structure,
- Colons (:) are used to represent the key-value pair (<key>: <value>), YAML files are mostly a form of key-value pair where the key represents the pair’s name and the value represents the data associated with that name.
- Dashes (-) are used to represent the Sequences/lists.
YAML data types: YAML has three types of data types:
- Scalar.
- Sequences.
- Dictionary.
Scalars: Values in YAML's key-value pairs are scalar, which represent a single stored value. Scalars are assigned to key names using mapping. A mapping can be defined with a name, colon (:), and space, then a value for it to hold. In short, scalar is a simple data type. In YAML, scalar means a simple value for a key. The value of the scalar can be integer, float, Boolean, and string. It's usually good enough to enclose strings in quotes, leave numbers unquoted, and let the parser figure it out.
… image: 'docker-week3:latest' …
Sequences: are data structures similar to a list or array that hold multiple values under the same key. Sequences can have one of two different styles:
- Block style uses spaces to structure the document. It’s easier to read but is less compact compared to flow style.
… num: - 10 - 11 - 12 …
- Flow style allows you to write sequences inline using square brackets, similar to an array declaration in several programming languages.
… num: [10, 11, 12] …
Dictionaries: are collections of key-value pairs all nested under the same subgroup. Dictionaries are defined like mappings in that you enter the dictionary name, a colon, and a space followed by 1 or more indented key-value pairs.
… ports: - 8080:8080 - 8081:8081 - 8082:8082 …