How to handle db with docker-compose

I’m trying to understand how to make my particular case work, and I guess I need some guidance on how th approach this problem.
Here is how my project is structured

main/
  docker-compose.yml
  /project1
    Dockerfile
  /project2
    Dockerfile
  /.circleci
    config.yml

Now, both projects use my localhost PostgreSQL and connect using a DATABASE_URL set in a configuration file (in my .gitignore) which is

DATABASE_URL=postgresql://ngw:@docker.for.mac.localhost:5432/utelier?timeout=5000&encoding=utf8&pool=5

In production it will use AWS services.
I’m using in my circlci config - image: circleci/postgres:9.4 but I’m not entirely sure how I’m supposed to put all these bits together.
The way I figured could work is:

- run: 
    name: Setup Directory Database
    command: |
      cd directory
      bundle exec rake db:create
      bundle exec rake db:schema:load

But looks quite fishy.
I want the main container to connect to the postgres:9.4 container and initialize the database. docker-compose is using env_file so probably I need to write the configuration in some ways (???)
Suggestions? Thanks a lot, I appreciate it

ngw

If you are using a CircleCI PostgreSQL container in the image key, then that will merge a socket into localhost. However you’d have to expose that to Docker Compose in some fashion.

I run Docker Compose to do integration tests (around 10 containers pulled from my own registry) and to simplify things I pull a database into Docker Compose itself. Thus, instead of running it using the CircleCI approach, I just use on CircleCI container and do everything inside Docker Compose.

Give that a try, and if you get stuck, show us your docker-compose.yml and what problem you’re trying to solve in CircleCI using DC (building images? running tests? etc).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.