add init database
This commit is contained in:
parent
5016e88515
commit
4b2c440146
|
@ -322,6 +322,7 @@ services:
|
||||||
build: ./postgres
|
build: ./postgres
|
||||||
volumes:
|
volumes:
|
||||||
- ${DATA_PATH_HOST}/postgres:/var/lib/postgresql/data
|
- ${DATA_PATH_HOST}/postgres:/var/lib/postgresql/data
|
||||||
|
- ${POSTGRES_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
|
||||||
ports:
|
ports:
|
||||||
- "${POSTGRES_PORT}:5432"
|
- "${POSTGRES_PORT}:5432"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
*.sh
|
|
@ -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 $POSTGRES_USER;
|
||||||
|
# CREATE DATABASE myshop_db;
|
||||||
|
# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO $POSTGRES_USER;
|
||||||
|
# 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;
|
||||||
|
# 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;
|
||||||
|
# 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;
|
||||||
|
# CREATE DATABASE db3;
|
||||||
|
# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3;
|
||||||
|
# EOSQL
|
Loading…
Reference in New Issue