orchardup / docker-postgresql

Deprecated - use the official postgres image.
https://registry.hub.docker.com/_/postgres/
Apache License 2.0
103 stars 62 forks source link

multiple databases at startup #20

Open maslick opened 9 years ago

maslick commented 9 years ago

Is it possible to create multiple databases at startup?

docker-compose.yml

db:
    image: postgres
    environment:
        - POSTGRES_DB=db1
        - POSTGRES_DB=db2
        - POSTGRES_USER=user
        - POSTGRES_PASSWORD=pwd
        - POSTGRES_ROOT_PASSWORD=rootpwd
outrunthewolf commented 8 years ago

I would probably namespace them. So:

POSTGRES_DB_1="database=X;user=X;password=X"
POSTGRES_DB_2="database=X;user=X;password=X"

Perhaps a limit of 10 and you could do something like:

for i in $(seq 0 10);
do
    tmp='POSTGRES_DB_'${i}
    # And all other variables

    # Array
    arr=$(echo ${!tmp} | tr ";" "\n")

    for x in $arr
    do
        # Do the postgres logic to create that Database
    done
done