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

Minimize duplicated content in docker-compose.yml #10

Closed
tschaffter opened this issue Aug 4, 2020 · 2 comments
Closed

Minimize duplicated content in docker-compose.yml #10

tschaffter opened this issue Aug 4, 2020 · 2 comments
Assignees

Comments

@tschaffter
Copy link
Owner

The services defined in docker-compose.yml have a lot of configuration that overlap. There should be a way to reduce the amount of duplicated code using inheritance or templates.

@tschaffter tschaffter self-assigned this Aug 4, 2020
@tschaffter
Copy link
Owner Author

tschaffter commented Aug 4, 2020

The docker-compose keyword extends is no longer available in version 3 of docker-compose.

An alternative is to use a templating approach. The use of a script that injects the content into the template would be a drawback but not here since I'm already using one (debian.sh). However, this may mean that I would not longer be able to use docker-compose build <services>.

Looking at existing workarounds:

docker-compose run \
  -f ./docker/base.yml \
  -f ./docker/extended.yml

An alternative as suggested in the above link is to place the overriding information in a Bash script to have them at a single location. However, this would make it difficult to validate the data. Alternatively I could place the overriding information in a JSON file, but I would list the built-in docker tool that validate the configuration file. I could write my own based on a JSON Schema that I would write for only the properties that I intend to support. However maintaining this schema would require additional effort.

  • Using a templating program: The method adopted by the author of this comment relies on Liquid. After reading about Liquid, this looks like an overkill solution.

@tschaffter
Copy link
Owner Author

Update

The current approach is user friendly and enables to quickly build and test environment. The cost for reducing the amount of duplicated code in docker-compose.yml using the current version of docker-compose is outweighed by the importance of keeping a user-friendly interface. I will revisit this feature when it is really needed or when Docker adds a feature similar to extends.

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

No branches or pull requests

1 participant