Skip to content
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 compose files by allowing multiple files #2051

Merged
merged 12 commits into from Sep 21, 2015

Conversation

dnephin
Copy link

@dnephin dnephin commented Sep 15, 2015

Resolves #1987

Add support for specifying multiple -f arguments to docker-compose. Multiple files are merged onto each other to allow users to customize the composition for different environments.

The default overrides file is docker-compose.override.yml which is applied over the default docker-compose.yml if it exists.

@dnephin
Copy link
Author

dnephin commented Sep 16, 2015

Ok, I've added some basic docs to the reference, cc @moxiegirl for review

I think we'll probably want to add an example which uses this new default override file, but I hope we can work on that as a separate branch.


def get_default_override_file(path):
override_filename = os.path.join(path, DEFAULT_OVERRIDE_FILENAME)
return [override_filename] if os.path.exists(override_filename) else []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to log.info if you find an override file? You might be doing this somewhere and I missed it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't currently log anything about which file is picked if we hit the defaults. A log.debug() might be good for debugging.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Troubleshooting is the exact use case I was thinking of. :-D

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
…nfig doesn't import from cli.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
@dnephin
Copy link
Author

dnephin commented Sep 17, 2015

@aanand I think I've addressed your comments

Docs are updated as well, and added debug logging for filenames

@dnephin dnephin added this to the 1.5.0 milestone Sep 17, 2015
all_service_names = set(base) | set(override)
return {
name: merge_service_dicts(base.get(name, {}), override.get(name, {}))
for name in all_service_names

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this level of terseness effects the readability a bit too much and could do with expanding out, being a bit more verbose. However, I think that's something we can address in a separate PR and not block this one for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it hard to be verbose (at least in code!) and always aim for greater density. Let me know how I can make this more readable.

@mnowster
Copy link

Overall I think this is good and great to get in before code freeze and some concerns around increasing level of verbosity is non blocking, which can be addressed outside of this PR. 🌴

LGTM.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
aanand added a commit that referenced this pull request Sep 21, 2015
Extend compose files by allowing multiple files
@aanand aanand merged commit 18dbe1b into docker:master Sep 21, 2015
@dnephin dnephin deleted the extend_compose_files branch September 21, 2015 13:27
arm4b pushed a commit to arm4b/st2-packages that referenced this pull request Nov 28, 2015
From user side just run `docker-compose run`, from CI override config with circle file.
See `docker-compose` core developer description about using `docker-compose.override.yml`: docker/compose#2051 (comment)
arm4b pushed a commit to arm4b/st2-packages that referenced this pull request Nov 28, 2015
From user side just run `docker-compose run`, from CI override config with circle file.
See `docker-compose` core developer description about using `docker-compose.override.yml`: docker/compose#2051 (comment)
arm4b pushed a commit to StackStorm/st2-packages that referenced this pull request Nov 30, 2015
From user side just run `docker-compose run`, from CI override config with circle file.
See `docker-compose` core developer description about using `docker-compose.override.yml`: docker/compose#2051 (comment)
@Vanuan
Copy link

Vanuan commented Feb 13, 2017

Somehow I thought that docker-compose.override.yml would be applied even if I specified an additional file through -f. Isn't that the case?

@dnephin
Copy link
Author

dnephin commented Feb 15, 2017

It is not the case.

The default is -f docker-compose.yml -f docker-compose.override.yml . If you specify any -f the default is not used.

@Vanuan
Copy link

Vanuan commented Feb 16, 2017

The default is -f docker-compose.yml -f docker-compose.override.yml

If it were defaults, it would fail with "docker-compose.override.yml is not found"
Is there a flag to ignore the "file doesn't exist" error?

@dnephin
Copy link
Author

dnephin commented Feb 16, 2017

I left out that bit, but yes, the override is considered optional. There is no flag to define an optional config

@greggwon
Copy link

I have a complex C++ application that needs to build with a specific set of tools and libraries. I want to perform the build inside of a container, with everything installed into system directories /usr/lib, /lib, /usr/local/bin, /usr/local/lib etc. To do the build, I mount an "external: false" volume on /usr/local/src. In the Dockerfile, I just install linux with the build tools, and then cd to /usr/local/src, and do "git clone" to download the app which has submodule dependencies for the right versions of things for each branch/tag version I have. The build works. But, I then need to have an saved container without the /usr/local/src mount (and some secrets for GitHub access) that I can then use to run the application on the target hardware/environment. How can I startup the container again, without the volume mounted nor the secrets in view?

@glours
Copy link
Contributor

glours commented Oct 19, 2023

hey @greggwon
You should use multi-stage builds for this, a stage to build your source and a production one which only contains your final binary.
https://docs.docker.com/build/building/multi-stage/

For the secret and git credentials you can take a look to https://docs.docker.com/engine/reference/builder/#run---mounttypesecret and https://docs.docker.com/engine/reference/builder/#run---mounttypessh

@greggwon
Copy link

The problem is that I need the whole build environment because of the libraries that I am building and installing. But, I don't need the source tree I build from. I don't see how this removes the source tree from the resulting container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants