0

I am trying to create a postgres database that is seeable from another container by using docker-compose. I can link the containers, and I verified that they can see each other.

What my problem seems to be is that my postgres container is not being provisioned correctly. I have a script called create_db.sql and I place that inside the /db-entrypoint-initd.d/ directory where it runs the first line of the script, but does not make the table I ask it too.

Dockerfile in database:

FROM postgres:latest
ADD create_db.sql /docker-entrypoint-initdb.d/

docker-compose.yml:

version: '2'
services:
 web:
  build: .
  volumes:
    - .:/usr/app/src
  command: python /usr/app/src/dashboard/runserver.py
  ports:
    - "5000:5000"
  links:
   - postgres
   - rabbitmq
 postgres:
  image: postgres
  build: ./database
  ports:
    - "5432:5432"
 rabbitmq:
  image: rabbitmq 

create_db.sql:

CREATE DATABASE westvillage;
CREATE TABLE wvlogger(
        DEPT char(10),
        DATE date,
        TIME time,
        C0 int,
        C1 int,
        C2 int,
        C3 int,
        C4 int,
        C5 int,
        C6 int,
        C7 int
);

What am I doing wrong? I tried changing my sql script and that did not work, I tried the ENV in the dockerfile but those never seem to work as well.

Is there a better way to provision my prostgres container? Ideally, I would like it all to happen with a single docker-compose.yml, but I have not been successful at that.

2
  • 1
    See if this helps stackoverflow.com/questions/15251054/… Commented Mar 25, 2016 at 15:41
  • haha didn't even think about connecting after creating a database! I'll try this out when I'm back at my dev station and will post the results! Commented Mar 25, 2016 at 21:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.