Created
February 4, 2020 19:56
-
-
Save zar3bski/9b01bc3a1c932be37f51a0ec0d62939c to your computer and use it in GitHub Desktop.
Initiate multiple database Postgresql Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -n "$POSTGRES_DBS" ]; then | |
IFS=\| | |
for s in $POSTGRES_DBS ; do | |
pass=$(echo "$s" | sed 's/.*->//'); | |
user=$(echo "$s" | sed 's/->.*//'); | |
db=$user"_db"; | |
psql --username "$POSTGRES_USER" <<-EOSQL | |
CREATE USER $user WITH PASSWORD '$pass'; | |
CREATE DATABASE $db; | |
REVOKE CONNECT ON DATABASE $db FROM PUBLIC; | |
GRANT ALL PRIVILEGES ON DATABASE $db TO $user; | |
ALTER DATABASE $db OWNER TO $user; | |
EOSQL | |
done | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres: | |
image: postgres:12.1-alpine | |
restart: always | |
volumes: | |
- ./postgres_init:/docker-entrypoint-initdb.d | |
environment: | |
- POSTGRES_USER=P0stgr3sSup3rUs3r | |
- POSTGRES_PASSWORD=SomeAdminPassword | |
- POSTGRES_DBS=some_user->some_password|some_other_user->some_other_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment