Skip to content

Instantly share code, notes, and snippets.

@meysam81
Last active June 4, 2019 11:30
Show Gist options
  • Save meysam81/3f60beaa4d5c74707405c47128d941ac to your computer and use it in GitHub Desktop.
Save meysam81/3f60beaa4d5c74707405c47128d941ac to your computer and use it in GitHub Desktop.
multiple database for dockerized postgres
#!/bin/bash
for database in $(echo "$POSTGRES_MULTIPLE_DATABASES" | tr ',' ' '); do
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -h "$POSTGRES_HOST" <<EOSQL
CREATE USER "$database";
CREATE DATABASE "$database";
GRANT ALL PRIVILEGES ON DATABASE "$database" TO "$database";
EOSQL
done
exit 0
postgres-migrate:
image: postgres:11.3
container_name: name
hostname: name
volumes:
- "./postgres/init.sh:/init.sh"
command: bash /init.sh
restart: on-failure
environment:
POSTGRES_HOST: "host"
POSTGRES_USER: "user"
PGPASSWORD: "pass"
POSTGRES_MULTIPLE_DATABASES: comma_separated_dbs
depends_on:
- postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment