Compose: docker-compose run with isolated sets of services?

Created on 2 Jul 2015  路  2Comments  路  Source: docker/compose

I have the following setup:

db:
  image: postgres:latest

app:
  ...
  links:
    - db

When I try to run docker-compose run app testcommand twice, it reuses the db container. Is it possible to make app create another db container?

What I'm after is:

  • app_run_1 ---> db_1
  • app_run_2 ---> db_2

I'm trying to isolate the services in order to run tests concurrently.

kinquestion

Most helpful comment

You can achieve this by running each command with a different project name. Use the --project-name flag or the COMPOSE_PROJECT_NAME environment variable:

$ docker-compose --project-name=p1 run -d app testcommand
# creates p1_db_1, p1_app_run_1
$ docker-compose --project-name=p2 run -d app testcommand
# creates p2_db_1, p2_app_run_1

All 2 comments

You can achieve this by running each command with a different project name. Use the --project-name flag or the COMPOSE_PROJECT_NAME environment variable:

$ docker-compose --project-name=p1 run -d app testcommand
# creates p1_db_1, p1_app_run_1
$ docker-compose --project-name=p2 run -d app testcommand
# creates p2_db_1, p2_app_run_1

Works like a charm. Thank you and @bfirsh for fig and compose, it's been really helpful. Keep up the good work guys.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maltefiala picture maltefiala  路  3Comments

saulshanabrook picture saulshanabrook  路  3Comments

foxx picture foxx  路  3Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  3Comments

dimsav picture dimsav  路  3Comments