← Back to Blog

YAML Anchors & Aliases: Reuse Values Without Duplication

How to use YAML anchors and aliases to DRY your config files. With examples for Docker Compose, Kubernetes, and CI/CD.

Basic Syntax

defaults: &defaults\n  adapter: postgres\n  host: localhost\n  port: 5432\n\ndevelopment:\n  <<: *defaults\n  database: myapp_dev\n\nproduction:\n  <<: *defaults\n  host: prod-db.example.com\n  database: myapp_prod

Try It Free

Use our free online tool — 100% client-side, no data leaves your browser.

Open YAML Validator

Related Tools & Articles