1

I am trying to spin a postgres container from docker-compose, copying *.sql files to /docker-entrypoint-initdb.d in order to create the database and the schema.

The logs from the docker-compose run:

/usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/02-schema.sql
db_1          | CREATE DATABASE
db_1          | GRANT
db_1          | SET
db_1          | CREATE TABLE
db_1          | CREATE INDEX
db_1          | CREATE TABLE
db_1          | CREATE TABLE

The database is created, but non of the tables is created. Below is my schema.sql file

CREATE DATABASE sample_db OWNER user1;
GRANT ALL PRIVILEGES ON DATABASE sample_db TO user1;


CREATE TABLE PUBLIC.PROFILES(
    USER_ID VARCHAR(50) PRIMARY KEY,
    NAME VARCHAR(50) NOT NULL
);

I used to do the same with my sql container, adding : USE sample_db, but I couldn't find the equivalent postgres command.

1 Answer 1

6

Have you use the POSTGRES_DB environment variable in the docker file? If it isn't set it will use the POSTGRES_USER as database name

Check the environment variable in the documentation https://hub.docker.com/_/postgres

Sign up to request clarification or add additional context in comments.

1 Comment

After setting this environment variable the tables defined in the init.sql script were all created. Works great, thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.