How to DRY Docker Compose files
extends attribute in Docker Compose files allows to reuse existing service definitions for other services.
That makes it possible to DRY Compose files.
name: foo
service:
dev:
image: ruby:3.3.5-alpine3.20
environment:
ENV: "development"
test:
extends:
service: dev
environment:
ENV: "test"In the definition above test service has exactly the same configuration dev and only redefines one environment variable.
According to the documentation it’s also possible to include and reuse definitions from other files.
- TIL rating:
- good to know