Docker Community Forums

Share and learn in the Docker community.

How would you define a non-running-by-default service?

Reduced docker-compose (it’s quite a bit more involved):

version: '2’
services:
postgres:
image: postgres:9.5
maven:
build: ./app-maven
volumes:
- ./app:/app-source
- app:/app
- m2:/home/build/.m2
tomcat:
build: ./tomcat
volumes:
- app:/app
links:
- postgres
volumes:
m2:
app:

Basic notion - I want services “tomcat” and “postgres” to run on docker-compose up. I would rather that “maven” ONLY run on “docker-compose run maven”, but not necessarily run (and take 8-10 minutes of compile time) on “docker-compose up”. I want them inter-related (named volume that is shared) but different containers.

Which would you choose (or, more to the point, am I missing a better option)?

1.) always do “docker-compose run -d postgres tomcat” instead of "docker-compose up"
2.) Modify “maven” to have a no-op RUN statement, then the real run becomes “docker-compose run maven maven-run.sh

option 3 would be suggesting an “autorun: false” option for the next docker-compose schema