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 }
More on Docker Compose
What is Docker Compose and what problem does it solve?Beginner`docker-compose` vs `docker compose`?BeginnerShow a minimal Compose file with a web app and a database.BeginnerWhat does `depends_on` guarantee?IntermediateHow do containers in Compose reach each other?BeginnerHow does Compose choose the project name and why does it matter?Intermediate