Add auto_up option to exclude service from docker-compose up
by default
#7548
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This an updated version of #3047, now complete with added test cases.
This adds the new config option
auto_up
to services. When this is explicitly set tofalse
the service will not be started when executingdocker-compose up
without service names (unless it is pulled in as a dependency of another service).This allows to define optional services in a
docker-compose.yml
which are only started when listed explicitly on the command line.Resolves #6742, #1896 and many more reports requesting this feature or similar.
Use case
For one example use case of the many listed in #1896 and linked issues consider the following
docker-compose.yml
:This may be an example of a prototypical web app running on PHP and using a MySQL database. Most of the time one only wants to run the
app
anddb
service but for debugging/development purposes two additional, optional services are defined here:phpmyadmin
: simple web interface to access and manipulate the raw databasemailhog
: a mocked mail transfer agent to be able to test and debug e-mails sent by the applicationThis now allows to start the main services with a simple
docker-compose up
and the optional services by listing them:Implementation details
This feature is realized by slightly changing
get_services
in theProject
module. If no service names are passed via the command line it falls back to all services in thedocker-compose.yml
- which are now filtered for services which haveauto_up
explicitly set tofalse
.When
auto_up
is set totrue
or is omitted the services are included in the default set as before. Additionally this change only affects thedocker-compose up
anddocker-compose create
commands. Consider thisdocker-compose.yml
:With this
docker-compose
behaves as follows:Alternatives
Currently the only way to achive this is by splitting the services into multiple
docker-compose.yml
files and pass them via the--file
parameter:As can be seen this is quite cumbersome and especially when using
docker-compose
for local development this a huge inconvenience as discussed in #1896 extensively and is confirmed by the amount of feature request for many years.This PR now adds the simple option
auto_up
to the schema from version 2.0 up.Documentation
The documentation for this option can be found - and later merged from - here: acran/docker.github.io@03ce9ed
References
This or a similar feature was requested in: #6742 (most recent discussion), #1896 (main discussion), #3047 (previous PR), #697, #912, #1294, #1439, #1547, #2803, #3027, #3289
also related: #1661, #1988, #2773, #3684, #4096, #4650, #6676