Last active
July 9, 2024 07:10
-
-
Save briceburg/2d401427c97ded0f408a918a8cac10b2 to your computer and use it in GitHub Desktop.
official PostgresSQL docker images - create multiple databases
This file contains hidden or 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/bash | |
set -e | |
if [ -n "$POSTGRES_DATABASES" ]; then | |
echo "POSTGRES_DATABASES provided. Creating multiple databases..." >&2 | |
IFS=', '; for db in $POSTGRES_DATABASES; do | |
echo "Creating '$db'" >&2 | |
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-ESQL | |
CREATE USER "$db"; | |
CREATE DATABASE "$db"; | |
GRANT ALL PRIVILEGES ON DATABASE "$db" TO "$db"; | |
ESQL | |
done | |
fi |
This file contains hidden or 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
--- | |
version: '3.7' | |
services: | |
postgres: | |
image: postgres:11.7 | |
environment: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DATABASES: database-larry, database_curly, moe | |
volumes: | |
- create-postgresql-databases.sh:/docker-entrypoint-initdb.d/create-postgresql-databases.sh:ro |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment