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

Add overwrite strategy options to config #3939

Closed
wants to merge 1 commit into from

Conversation

CarstenHoyer
Copy link

@CarstenHoyer CarstenHoyer commented Sep 12, 2016

This PR introduces two new configuration options; override_strategy and overwrite.

override_strategy: Can be either 'default' or 'overwrite'. Default does nothing except being explicit. 'Overwrite' overwrites the base config with the override config.

overwrite: If override_strategy is set, this does not apply. Otherwise it will look at all the fields in the overwrite array and again overwrite the base config with the override config.

Note there is currently no tests, I wanted to just see if there was any interest in this PR first.

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "override-strategy" [email protected]:CarstenHoyer/compose.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f

Ammending updates the existing PR. You DO NOT need to open a new one.

@CarstenHoyer
Copy link
Author

CarstenHoyer commented Sep 13, 2016

It could be made simpler by just including the overwrite option and not the override_strategy option.

I have prepared a branch for that: https://github.com/CarstenHoyer/compose/tree/overwrite

@CarstenHoyer CarstenHoyer force-pushed the override-strategy branch 3 times, most recently from 1442404 to c8a91c1 Compare September 16, 2016 19:26
@bharley
Copy link

bharley commented Dec 13, 2016

There hasn't been any activity on this in a while, is there any possibility this (or something similar) might make it in?

@fabricionaweb
Copy link

+1

@ababushkin
Copy link

Any chance this one can get merged (pending the conflict resolution of course)??

This is quite useful for non-trivial multi-container apps.

@CarstenHoyer
Copy link
Author

I haven´t gotten any feedback from Docker about this issue. I am ok rewriting it, if you think it should follow some different approach. But it would be nice to hear, if you think the idea in the feature, could be merged at some point.

Thanks

@bluemoehre
Copy link

I would also love to have this option.
E.g. if you have lots of containers from different sources, you may run in port conflicts. You won't need to touch or copy the original config if it would be possible to overrwrite the ports instead of extending. This simplifies the container management a lot.

@gligoran
Copy link

gligoran commented May 1, 2017

Any news on this?

@bluemoehre
Copy link

I am afraid there was no progress - totally disappointing. Still have to use workarounds.

@vinyll
Copy link

vinyll commented Jun 27, 2017

Sooo looking forward for this feature.
Maybe a fork of docker-compose if Docker is not willing to merge this nor implement a similar functionality?

@topiaruss
Copy link

It's a shame that this has not been merged or resolved.

@codeasone
Copy link

This would be a helpful.

@sobolevn
Copy link

sobolevn commented Nov 6, 2017

Totally agree, this solves the ports issue.

@Mobe91
Copy link

Mobe91 commented Nov 22, 2017

Will this be merged any time soon?

@pklingem
Copy link

pklingem commented Jan 4, 2018

@docker there's clearly a community desire for this feature, it'd be nice to know one way or another if it or something similar might be added to docker-compose.

@xenithorb
Copy link

@shin- @aanand Is this on your guys' radar? Would really like to see this happen!

@mykola-dev
Copy link

it looks like docker-compose is abandoned. we should create a community fork.

@nevergone
Copy link

@CarstenHoyer Please write test. Thanks.

@sharksforarms
Copy link

Any updates?

@CarstenHoyer
Copy link
Author

I am closing this pull request. I am not working with this anymore, so I can't keep it updated or write tests. Please reference this issue in a new request.

@keithy
Copy link

keithy commented Oct 31, 2018

Checkout how taurus does their config. Temped to repurpose their code into a docker compose wrapper

@twitchard
Copy link

I'm just going to experiment with generating docker-compose.yaml from dhall-lang which can generate yaml easily and has more flexible import and override semantics built-in.

@J7mbo
Copy link

J7mbo commented Mar 23, 2020

Just wondering - why was this ignored by the docker team? No response or anything, is it just not useful and they disagree with it, no time?

@cbrunnkvist
Copy link

cbrunnkvist commented Jan 27, 2021

For now - without the ability to overwrite objects - we instead have to move the ports and other complex objects into yet another file, which we can cascade e.g.:

# docker-compose.yml
...
  some-svc:
    image: xyz:${RELEASE:-latest}
...
# docker-compose.prod.yml
...
  some-svc:
    env:
      - "X=y"
...
# docker-compose.local-ports.yml
...
  some-svc:
    ports:
      - "3000:3000"
...
# docker-compose.ci.yml
...
  some-integration-test-svc:
    ...
...

Generate a "production" (🤷) config to ship somewhere:

COMPOSE_FILE="docker-compose.yml:docker-compose.prod.yml" docker-compose config > docker-compose.${RELEASE}.conf

Run a composition for dev:

COMPOSE_FILE="docker-compose.yml:docker-compose.ports.yml" docker-compose up

Run a composition for some integration test:

COMPOSE_FILE="docker-compose.yml:docker-compose.ports.yml:docker-compose.ci.yml" docker-compose up --build --abort-on-container-exit

Not the end of the world, but a bit annoying.

@mstate
Copy link

mstate commented Jun 2, 2023

I wanted to remove ports from my config files when executing in a devcontainer. So, I used fish shell and yq. Hopefully, someone will find this useful.

I added this to a fish config file in my ~/.config/fish/conf.d/ folder:

function config_file
  docker compose -f $THRIVE_SOURCE_DIR/docker-compose.yml -f $THRIVE_SOURCE_DIR/docker-compose.dev.yml config | yq 'del(.services[].ports)' | psub
end

Then, to use it:
docker compose -f (config_file) up -d

@gpetraroli
Copy link

gpetraroli commented Apr 24, 2024

For those interested there is a simpler way to achieve this:

  • In the docker-compose.yaml create the config without ports mapping
  • Create a docker-compose.override.yaml where you configue your ports for dev enviroment for example

At this point when you run docke compose up you have the same container as you would configuring all in the docker-compose.yaml

  • For the other enviroments create a docker-compose.override.prod.yaml where you override the ports mapping specifically for that enviroment.

To build the containers run docker compose -f docker-compose.yaml -f docker-compose.override.prod.yaml up

Hope this helps!

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.