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.

Kyle Calica-St
  • 2,629
  • 4
  • 26
  • 56

0 Answers0