-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend a base service from the same file #1988
Comments
Signed-off-by: Karol Duleba <mr.fuxi@gmail.com>
Do you have some examples of this? I've never seen it myself, and I'm having a hard time understanding why you would ever need this? If you want to share a bunch of common environment you can use an env_file, or even a data volume container with volumes_from. |
I think supporting abstract services might be a mistake. The only requirement for a service is to have an |
You can always set a command of |
Actually, I think that fix lands in 1.5. |
Currently I am using YAML node anchors, but this proposal could be more useful. That works this way:
When extending other file, it also requires the |
This is now in the 1.5.0 release. The rest is covered by #1896 |
I'd like to have a common base that includes dns and dns_search options, will look at the YAML node anchors workaround for now. |
Reopening because @fxdgear has run into this issue running some internal Docker stuff. We should either:
My concern is that using a fake command is a hack – and isn't obvious when reading the Compose file what the intent of that is. I think (1) would work as a stop gap, but I think we should probably do (2) at some point. |
Also another idea from @fxdgear: maybe these things could live under a different key? Example above would look like:
The reason I dislike this is it would mean having a new top-level key for each type of object we add to Compose files (networks, volumes, etc). |
I think that abstract base services are one half of the problem. They cover the case where you have services which are very similar, sharing most of their defined attributes. However, many services still need to share common subsets of attributes (frequently if there is a one-to-many relationship between some set of containers - e.g. a database or a queue - where all client services will share configuration). In that case, a single abstract base class doesn't buy you much. There's a longer ticket with more discussion over here if you are interested: #3167. |
So, what is the current state, is it possible to extend service from current docker-compose.yml? |
@whitecolor idk but I think The recommended replacement, where you specify multiple compose yml files in COMPOSE_FILE and they are merged, doesn't really satisfy this use case. In docker-compose 1.14.0 how do people reuse common configuration of a service when defining other services? |
@jamshid probably not typical approach for a medium project I prefer to use dynamic docker-compose config that is produced from JS (TypeScript) configuration. But it works much better than dancing around docker-compose.yml format, yaml anchors, etc. |
Specifying multiple Compose files doesn't satisfy this use case. (I ran into this problem again today.) |
Addressed in #5140 |
Sorry, I still don't quite see what solution is now (from #5140). Could someone point me to the docs? |
2020 year. |
2021 |
2022 |
2023 |
2023 😢 |
2023 |
2024 |
@dfyz011 @izakdvlpr (and the rest) Isn't this achievable already (since 2017) via Extension Fields? Using the example above, you could do
|
It is not, the extension fields override nodes of the same name. So for example it will override my entire environment. |
It is a common pattern to define a base service which you want several services to extend, but it's currently very verbose to do this:
docker-compose-base.yml
docker-compose.yml
It should be possible to extend an incomplete service in a single compose file. Something like this:
Design decisions:
The text was updated successfully, but these errors were encountered: