YAML anchors to avoid repeating yourself

Yaml

Define a block once, merge it into each service. Changing the base changes all of them.

x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 10m

services:
  api:
    <<: *defaults
    image: example/api:1.4.0
  worker:
    <<: *defaults
    image: example/worker:1.4.0

More in Data Formats

Random picks