I posted this question originally on the Docker forums, but didn't get any response there.
I'm wondering what the best way would be to model a set of services let's call them db
, web
, and batch
. db
is simply a running database server instance (think MySQL). web
is a web application that needs to connect to the database. batch
is a batch application that needs to connect to that same database (it can/will run in parallel with web
). db
needs to be running, for either web
or batch
to run. But web
or batch
can be run independently of each other (one or both can be running at the same time). If both are running at once, they need to be talking to the same database instance (so db
is actually using volumes_from
a separate data volume container). So if the use case was simpler (think just db
and web
, which always run together), then they would simply both be defined as services in the same compose file, with web
having a link to db
.
As far as I understand it, these can't all be defined in the same Docker compose configuration. Instead, I would need three different configurations. One for db
, which is launched first, one for web
(which uses external_links
to find db
), and a third for batch
(which also uses external_links
to find db
). Is that correct, or is there some mechanism available that I'm not considering? Assuming a multi-configuration setup is needed, is there a way to "lazily" initialize the db
composition if it's not running, when either the web
or batch
compositions are launched?