diff --git a/Dockerfile b/Dockerfile index ee9c3d0..efba395 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,2 @@ -FROM postgres:9.6 +FROM postgres:12.6-alpine COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index aa665fa..898aff6 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -7,7 +7,7 @@ function create_user_and_database() { local database=$1 echo " Creating user and database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - CREATE USER $database; + CREATE USER $database PASSWORD '$database'; CREATE DATABASE $database; GRANT ALL PRIVILEGES ON DATABASE $database TO $database; EOSQL diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bced875 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + db: + image: postgres-multi-db + restart: always + ports: + - "5432:5432" + environment: + - POSTGRES_MULTIPLE_DATABASES=db1,db2 + - POSTGRES_USER=dbuser + - POSTGRES_PASSWORD=dbpass \ No newline at end of file