Interview Prep/Docker/Docker Compose

What does `extends` and YAML anchors give you for DRY config?

IntermediateConceptDocker Compose
Answer

Use x- extension fields with anchors for shared blocks; include: to pull in other Compose files; and extends to reuse a service definition.

x-common: &common
  restart: unless-stopped
  logging: { driver: json-file, options: { max-size: "10m", max-file: "3" } }
services:
  api: { <<: *common, image: api:1 }
  worker: { <<: *common, image: worker:1 }
All Docker questions Roadmap: Docker & containers

More on Docker Compose