Docker compose extend
duplicating a Redis service in every docker-compose file, today I learned that compose configurations can be shared across file and projects.
// monorepo/docker-compose.yml version: "3" services: redis: image: redis:5.0.6 ports: - 6379:6379 (...) // other shared dependencies
In this setup, Redis is added to the top-level docker-compose file and is extended in the services docker-compose file. If we now up the service with yarn workspace my-service up it will check for Redis in the top-level up it, and continue to add the dependencies as they are defined in the services docker-compose.
// monorepo/packages/my-service/docker-compose.yml version: "3" services: redis: extends: file: ../../docker-compose.yml service: redis (...) // other service dependencies