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 put the following script based on an example I found online:
#!/bin/bash
echo "******CREATING DOCKER DATABASE******"
gosu postgres postgres --single <<- EOSQL
CREATE DATABASE orpheus;
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 ""
echo "******DOCKER DATABASE CREATED******"
The backslashes seem required since otherwise I get a parse error. The script runs without error and all of the commands except for the CREATE TABLE commands seem to have had an effect.
Is it that table creation is not supported in single user mode? If so, is there a better way to have a dockerfile set up an image with tables created in postgres?
listen_addresses = ''and use a unix socket, orlisten_addresses = '127.0.0.1, ::1' (via the-c` argument topostgres) and use a loopbackpsqlsession, do what you need to do, and restart Pg for general access, but the Docker folks seem to prefer a quick hack to a robust solution most of the time...