Reputation: 65
Let's say I have a service like:
my-service:
build:
context: "./my-service"
dockerfile: Dockerfile.dev
ports:
- 8072:8000
depends_on:
- another-service
environment:
PROXY: "true"
And I want to create my-service-2
with exactly the same configurations but only with different port. I could do this:
my-service-2:
build:
context: "./my-service"
dockerfile: Dockerfile.dev
ports:
- 8073:8000
depends_on:
- another-service
environment:
PROXY: "true"
But is there any way I could do something like:
my-service-2 extends my-service:
ports:
- 8073:8000
So I wouldn't need to rewrite the same thing many times.
Thanks!
Upvotes: 6
Views: 3013
Reputation: 322
Extends is supported till compose v2.1 although its usage is not how you asked for.
You need to keep the common configurations in one compose file and in the docker-compose.yml you can define the services extending from the common compose configuration.
Here is an elaborate example and documentation on this: https://docs.docker.com/compose/extends/
Upvotes: 3