YAML
YAML is a relatively simple, human readable data format, used principally in configuration type scenarios. For example, in this book we will use YAML to configure the following components:
- Docker Compose
- GitHub Actions
It can have other uses, (e.g. data interchange), but personally I’ve not come across that too much in the wild.
YAML originally stood for Yet Another Markup Language but has evolved to now represent YAML Ain’t Markup Language.
Personal Opinion: While it makes no difference to the use of YAML, I personally preferred the original definition.
Key Features
- Human-readable: Its syntax is easy to understand.
- Supports hierarchical data: Ideal for representing complex data structures like lists and dictionaries.
- Indentation-based structure: YAML relies on indentation to represent nested elements. - while this is a feature it is often cited as a reason why YAML can be difficult to debug
- Flexible data types: Supports strings, numbers, booleans, dates, and null values natively.
Basic Syntax
- Uses indentation to denote structure
- Key-value pairs are used for mappings
- Hyphens are used to create lists
As a refresher, here’s the docker-compose.yaml file we created in Iteration 1:
services:
postgres:
image: postgres:latest
container_name: postgres_db
ports:
- "5432:5432"
environment:
POSTGRES_DB: commands
POSTGRES_USER: cmddbuser
POSTGRES_PASSWORD: pa55w0rd
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
driver: local
Alternatives
- JSON
- XML
- TOML