Im trying to create a Dockerfile from the postgres image. The repo says that initialization should be handled by placing a shell script in /docker-entrypoint-initdb.d/. I pu
I tested your script and it is almost working fine. Using Postgresql 9.4 I managed to make the following to work:
gosu postgres postgres --single -jE <<- EOSQL
CREATE DATABASE orpheus;
EOSQL
echo
gosu postgres postgres --single -jE orpheus <<- EOSQL
CREATE USER docker WITH ENCRYPTED PASSWORD 'pwd_docker';
GRANT ALL PRIVILEGES ON DATABASE orpheus to docker;
CREATE TABLE profiles (
profile_id SERIAL UNIQUE PRIMARY KEY,
user_id integer NOT NULL UNIQUE,
profile_photo_id integer NOT NULL UNIQUE,
age integer
);
CREATE TABLE hidden_user (
owner_id integer NOT NULL PRIMARY KEY,
target_id integer NOT NULL
);
EOSQL
echo
Basically I had to split the script in two as the postgresql was complaining that the create database
couldn't be used in multiline scripts. And the other was only to add the database name, orpheus
, on the second command.
And voilà