Skip to content

Commit

Permalink
Merge pull request laradock#1614 from ahkui/postgresql_init_db
Browse files Browse the repository at this point in the history
add postgres init db
  • Loading branch information
bestlong authored Jun 22, 2018
2 parents 5bffd43 + 7199ae5 commit 154249a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ services:
build: ./postgres
volumes:
- ${DATA_PATH_HOST}/postgres:/var/lib/postgresql/data
- ${POSTGRES_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
ports:
- "${POSTGRES_PORT}:5432"
environment:
Expand Down
1 change: 1 addition & 0 deletions postgres/docker-entrypoint-initdb.d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh
34 changes: 34 additions & 0 deletions postgres/docker-entrypoint-initdb.d/createdb.sh.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
#
# Copy createdb.sh.example to createdb.sh
# then uncomment then set database name and username to create you need databases
#
# example: .env POSTGRES_USER=appuser and need db name is myshop_db
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER myuser WITH PASSWORD 'mypassword';
# CREATE DATABASE myshop_db;
# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO myuser;
# EOSQL
#
# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found.
#

set -e
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db1 WITH PASSWORD 'db1';
# CREATE DATABASE db1;
# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1;
# EOSQL

# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db2 WITH PASSWORD 'db2';
# CREATE DATABASE db2;
# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2;
# EOSQL

# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db3 WITH PASSWORD 'db3';
# CREATE DATABASE db3;
# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3;
# EOSQL

0 comments on commit 154249a

Please sign in to comment.