Simplify Your Docker Setup with Extensions in 'compose.yml'
To write an extension in a compose.yml file for Docker, you can use the x- prefix to define reusable fragments of configuration. Here's an example demonstrating how to use extensions in compose.yml:
Example compose.yml with Extensions
version: '3.8'
# Define extensions
x-common-environment: &common-environment
environment:
- NODE_ENV=production
- LOG_LEVEL=info
x-common-volumes: &common-volumes
volumes:
- data:/data
services:
web:
image: my-web-app:latest
<<: *common-environment # Include common environment variables
<<: *common-volumes # Include common volumes
ports:
- "80:80"
worker:
image: my-worker-app:latest
<<: *common-environment # Include common environment variables
<<: *common-volumes # Include common volumes
environment:
- WORKER_TYPE=background
volumes:
data:
Key Points:
This method helps maintain a clean and maintainable compose.yml file by avoiding repetition.
Interesting! Great insights..
Love this