-
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 from multiple services as mixins #3167
Comments
I requested this. Here is why. Containers share configuration; usually when there is a one-to-many relationship going on. If you want to define a database and have several containers access it then all of those containers are going to need to know the DSN, along with some other settings that form a little collection. I think that using env_file declarations is a non-solution to this, as it only address environment variables and not other declaration types. I might want this little collection of settings to include a I think that a mixin-style approach would be a very neat solution. Through it we would be able to cleanly group all configuration relating to the access of a particular container, right there in the same docker-compose.yaml. And, if you think about it, we are half-way there already. We have the |
@dnephin I saw that you downvoted the original issue. I have added some reasoning and would be interested in your opinion. |
Thanks for adding more information. There is always a trade-off between being more explicit (adding the options to every service) and trying to reduce duplication (supporting ways to share options). It almost sounds like what is desired here is something like "roles" (as it would be called in puppet), were you can assign a block of options because the node has some role (db client). So far in my experience I've always opted to try and keep the options specified in the compose file to a minimum. Once it starts to grow, I'll move it to a file and use I would agree with "prefer composition over inheritance", however I don't see mixins as composition, mixins are multiple-inheritance. If we wanted to use composition, maybe one way to do that would be to support an idea of a "role". |
@dnephin Indeed, I also think this is related to config management. I imagine chef, salt, ansible, et al. have an equivalent to puppet's roles. I think that multiple inheritance, mixins, and this concept are in a similar space, especially because we are limiting ourselves to data representation (there's no polymorphism, method overloading, etc. when you're talking about a config file). However, I think that this is a bit different to how roles operate, because with roles you are composing modules together and I don't think that they interact all that much (?). Whereas here we want to be able to interleave the definitions. Stripping it down, the concrete behaviour needed is to define the shared "atoms" once, usually as part of aggregate sets, and be able to create aggregates of those aggregate sets. I can think of three classes of atoms present in docker-compose.yml files:
For each some form of aggregating behaviour must be defined:
I think that there are two main use-cases. Firstly where the service "is-a" type of a common base service, and secondly where the service "has-a" common collection of settings (OO terms only used here for the purpose of analogy). Applications (or some subset of services) which look like:
It seems that there have been a number of efforts to solve this problem that have each provided a part-solution. The extends definition, multiple files passed on the command line, env_file declarations, and variable substitution are all different ways to switch out parts of the docker-compose.yml file under different circumstances. I think that the approach outlined here could obviate much of the need for the first three, and potentially provide a better way to switch out settings that differ between dev/test/prod (which is I think the main utility of variable substitution). I think that ultimately the most intuitive way to represent this is all in one place - in the docker-compose.yml file - rather than being woven through an assemblage of discordant files which are awkwardly, and confusingly, tangled up together. I'm currently using the following code to achieve this, though I'd much _much_ rather use something native https://gist.github.com/dunk/8d258be750c7da048f52 |
I can understand how mixin-like behaviour would replace/enhance Could you clarify how you see mixins working to serve the same use cases? |
@aanand Sure thing. On closer examination I was wrong about multiple There are two aspects at play - env-dependant composition and reusable grouping.
Of course, |
Is there any chance of this issue being on the roadmap at the moment? |
As for shared configuration inside the docker-compose.yml -- I would look into yaml anchors ('variables' for sharing structure/values). As for true mix-ins (what you are asking for)-- I believe (and please correct me if I'm wrong), but the role of docker-compose, specifically, is to handle already built images and putting them together in a cohesive set of inter-working containers. Mix-ins seem to me hinting towards the image creation process sharing functionality, not containers. On the image building side-- while it may be a bit hackish-- I am currently working on a project that involves packaging up functionality (such as loading zsh, oh-my-zsh, vim, etc.) into a shell script that are executed (and therefore added as an image layer) given a specific --build-arg such as |
@colinross Anchors don't solve this problem - only a subset. You cannot, for instance, interleave items from dictionaries or lists - you can only reference a static predefined lump of stuff. I think that the mix-ins idea is actually inevitable. There are many things that are going to apply to multiple containers - a database username / password combo, for instance, for every container which accesses that container. While this particular case can be solved by an env var file, other cases can't (particularly when groups of directives cluster - say a Indeed that is a hack. Wouldn't it be nicer if there was a way to have it built in? |
Hello, |
I would still love it too, fwiw. |
Almost 1 year passed - any news? I would also love that feature |
True love never dies :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as not stale anymore due to the recent activity. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it had not recent activity during the stale period. |
I would also like to vote on this issue being resolved. I am working with a memory constrained environment and would like to create a file called
I'm about to start figuring out a way around this in the meantime, but the workaround is gonna be hacky and the code will be spaghetti. |
I would find this feature very useful My scenario:I have a system where we have multiple microservices and we use docker compose for integration testing locally. We have 2 main compose files, 1 for normal test and 1 with debug capabilities, as well as 1 with common services. There are 3 compose files:
where in common.yml there are common 3pp services used in both scenarios and a base definition with common config shared among our services. in docker-compose.yml each service is defined and extends from the common service definiton in debug.yml each service extends from it's docker-compose.yml counterpart. |
It has been requested that extending services should work with multiple services, where each one may add additional bits of configuration.
Something along these lines:
The text was updated successfully, but these errors were encountered: