Docker Community Forums

Share and learn in the Docker community.

Application modeling question, and any way to control service name?


(Jeffevans) #1

My first question is simple. Is it possible to control the service name that is launched by Docker compose? For example, if I have a compose file that contains a service named “myservice” in a directory named “myapp”, the service name ends up being “myapp_myservice_1”. Is there any way to control this name, either in the YML configuration or at runtime?

Also, 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 the database. 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, with web having a link to db.

As far as I understand it, these can’t all be defined in the same yml 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). But is there a way to “lazily” initialize db if it’s not running, when either the web or batch compositions are launched?