From 0e588303a4c5459440507349a10cf93a578da79f Mon Sep 17 00:00:00 2001 From: Dirk Grunwald Date: Thu, 27 May 2021 16:26:52 -0600 Subject: [PATCH 1/5] make turn-key example using docker compuse up --- create-multiple-postgresql-databases.sh | 22 -------------------- docker-compose.yml | 15 +++++++++++++ script/create-multiple-postgres-databases.sh | 20 ++++++++++++++++++ 3 files changed, 35 insertions(+), 22 deletions(-) delete mode 100755 create-multiple-postgresql-databases.sh create mode 100644 docker-compose.yml create mode 100755 script/create-multiple-postgres-databases.sh diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh deleted file mode 100755 index aa665fa..0000000 --- a/create-multiple-postgresql-databases.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -set -e -set -u - -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 DATABASE $database; - GRANT ALL PRIVILEGES ON DATABASE $database TO $database; -EOSQL -} - -if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then - echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES" - for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do - create_user_and_database $db - done - echo "Multiple databases created" -fi diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6f380cf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.9" +services: + myapp-postgresql: + image: postgres:latest + volumes: + - type: bind + source: ./script + target: /docker-entrypoint-initdb.d + - type: bind + source: ./dbdata + target: /var/lib/postgresql/data + environment: + - POSTGRES_MULTIPLE_DATABASES=db1,db2 + - POSTGRES_USER=myapp + - POSTGRES_PASSWORD=changeme diff --git a/script/create-multiple-postgres-databases.sh b/script/create-multiple-postgres-databases.sh new file mode 100755 index 0000000..7eb8c5e --- /dev/null +++ b/script/create-multiple-postgres-databases.sh @@ -0,0 +1,20 @@ +# + +echo "Hi mom!" + +set -e +set -u + +if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then + echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES" + for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do + echo " Creating user and database '$db'" + echo psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL + CREATE USER $db; + CREATE DATABASE $db; + GRANT ALL PRIVILEGES ON DATABASE $db TO $db; +EOSQL + + done + echo "Multiple databases created" +fi From cfbc179b1723a5184aa33d94f023b11a995b28da Mon Sep 17 00:00:00 2001 From: Dirk Grunwald Date: Thu, 27 May 2021 17:36:22 -0600 Subject: [PATCH 2/5] make it specific to postgis --- test-db-for-gis.sh | 19 +++++++++++++++++++ users/users.txt | 4 ++++ 2 files changed, 23 insertions(+) create mode 100755 test-db-for-gis.sh create mode 100644 users/users.txt diff --git a/test-db-for-gis.sh b/test-db-for-gis.sh new file mode 100755 index 0000000..ec51cc6 --- /dev/null +++ b/test-db-for-gis.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Test named database for GIS sections +# + +while IFS= read -r dbuser; do + echo "dbuser is $dbuser" + read -r PGPASSWORD + echo "dbpasswd is $PGPASSWORD" + psql postgresql://$dbuser:$PGPASSWORD@localhost/$dbuser < Date: Thu, 27 May 2021 17:39:11 -0600 Subject: [PATCH 3/5] forgot to stage --- README.md | 129 +++++++++++++------ docker-compose.yml | 27 ++-- script/create-multiple-postgres-databases.sh | 46 +++++-- 3 files changed, 131 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 3db6ca3..ef017e9 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,102 @@ # Using multiple databases with the official PostgreSQL Docker image -The [official recommendation](https://hub.docker.com/_/postgres/) for creating -multiple databases is as follows: - -*If you would like to do additional initialization in an image derived from -this one, add one or more `*.sql`, `*.sql.gz`, or `*.sh` scripts under -`/docker-entrypoint-initdb.d` (creating the directory if necessary). After the -entrypoint calls `initdb` to create the default `postgres` user and database, -it will run any `*.sql` files and source any `*.sh` scripts found in that -directory to do further initialization before starting the service.* - This directory contains a script to create multiple databases using that mechanism. -## Usage +The following script uses the user and password information +in file ./users/users.txt to to create a database per user, +set the password for that database and then initialize the postgis +extensions. -### By mounting a volume +The user file should contain pairs of lines that are the user and password. +e.g. +``` +user1 +passwd1 +user2 +passwd2 +``` -Clone the repository, mount its directory as a volume into -`/docker-entrypoint-initdb.d` and declare database names separated by commas in -`POSTGRES_MULTIPLE_DATABASES` environment variable as follows -(`docker-compose` syntax): - myapp-postgresql: - image: postgres:9.6.2 - volumes: - - ../docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d - environment: - - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD= - -### By building a custom image +## Usage -Clone the repository, build and push the image to your Docker repository, -for example for Google Private Repository do the following: +* Create a directory 'dbdata' - if you need to re-create it, note that you'll need to use sudo + so `sudo rm -rf ./dbdata ; mkdir dbdata` is useful - docker build --tag=eu.gcr.io/your-project/postgres-multi-db . - gcloud docker -- push eu.gcr.io/your-project/postgres-multi-db +* Run `docker-compose up` -You still need to pass the `POSTGRES_MULTIPLE_DATABASES` environment variable -to the container: +This should create two database with output similar to: +``` +myapp-postgresql_1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-multiple-postgres-databases.sh +myapp-postgresql_1 | dbuser is db1 +myapp-postgresql_1 | dbpasswd is db1passwd +myapp-postgresql_1 | Creating user and database 'db1' +myapp-postgresql_1 | CREATE ROLE +myapp-postgresql_1 | CREATE DATABASE +myapp-postgresql_1 | GRANT +myapp-postgresql_1 | CREATE EXTENSION +myapp-postgresql_1 | CREATE EXTENSION +myapp-postgresql_1 | List of schemas +myapp-postgresql_1 | Name | Owner +myapp-postgresql_1 | ----------+------- +myapp-postgresql_1 | public | myapp +myapp-postgresql_1 | topology | myapp +myapp-postgresql_1 | (2 rows) +myapp-postgresql_1 | +myapp-postgresql_1 | List of relations +myapp-postgresql_1 | Schema | Name | Type | Owner +myapp-postgresql_1 | ----------+-----------------+-------+------- +myapp-postgresql_1 | public | spatial_ref_sys | table | myapp +myapp-postgresql_1 | topology | layer | table | myapp +myapp-postgresql_1 | topology | topology | table | myapp +myapp-postgresql_1 | (3 rows) +myapp-postgresql_1 | +myapp-postgresql_1 | GRANT +myapp-postgresql_1 | dbuser is db2 +myapp-postgresql_1 | dbpasswd is someother +myapp-postgresql_1 | Creating user and database 'db2' +myapp-postgresql_1 | CREATE ROLE +myapp-postgresql_1 | CREATE DATABASE +myapp-postgresql_1 | GRANT +myapp-postgresql_1 | CREATE EXTENSION +myapp-postgresql_1 | CREATE EXTENSION +myapp-postgresql_1 | List of schemas +myapp-postgresql_1 | Name | Owner +myapp-postgresql_1 | ----------+------- +myapp-postgresql_1 | public | myapp +myapp-postgresql_1 | topology | myapp +myapp-postgresql_1 | (2 rows) +myapp-postgresql_1 | +myapp-postgresql_1 | List of relations +myapp-postgresql_1 | Schema | Name | Type | Owner +myapp-postgresql_1 | ----------+-----------------+-------+------- +myapp-postgresql_1 | public | spatial_ref_sys | table | myapp +myapp-postgresql_1 | topology | layer | table | myapp +myapp-postgresql_1 | topology | topology | table | myapp +myapp-postgresql_1 | (3 rows) +myapp-postgresql_1 | +myapp-postgresql_1 | GRANT +``` - myapp-postgresql: - image: eu.gcr.io/your-project/postgres-multi-db - environment: - - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD= +## Test it out -### Non-standard database names +The script `./test-db-for-gis.sh` will loop through each user and question run postgres_version() to +insure that the postgis extensions are installed. It will also create a table that uses a `GEOM` +type which would fail if postgis is not setup correctly. -If you need to use non-standard database names (hyphens, uppercase letters etc), quote them in `POSTGRES_MULTIPLE_DATABASES`: +``` +beast-18$ ./test-db-for-gis.sh +dbuser is db1 +dbpasswd is db1passwd + postgis_full_version +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="130" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 5.2.0, September 15th, 2018" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.5.0 (Internal)" TOPOLOGY +(1 row) - environment: - - POSTGRES_MULTIPLE_DATABASES="test-db-1","test-db-2" +dbuser is db2 +dbpasswd is someother + postgis_full_version +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="130" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 5.2.0, September 15th, 2018" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.5.0 (Internal)" TOPOLOGY +(1 row) +``` diff --git a/docker-compose.yml b/docker-compose.yml index 6f380cf..b28317e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,12 @@ -version: "3.9" -services: - myapp-postgresql: - image: postgres:latest - volumes: - - type: bind - source: ./script - target: /docker-entrypoint-initdb.d - - type: bind - source: ./dbdata - target: /var/lib/postgresql/data - environment: - - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD=changeme +myapp-postgresql: + image: postgis/postgis:latest + volumes: + - ./script:/docker-entrypoint-initdb.d + - ./users:/opt-users + - ./dbdata:/var/lib/postgresql/data + ports: + - "5432:5432" + environment: + - POSTGRES_MULTIPLE_DATABASES=db1,db2 + - POSTGRES_USER=myapp + - POSTGRES_PASSWORD=changeme diff --git a/script/create-multiple-postgres-databases.sh b/script/create-multiple-postgres-databases.sh index 7eb8c5e..aba5fc7 100755 --- a/script/create-multiple-postgres-databases.sh +++ b/script/create-multiple-postgres-databases.sh @@ -1,20 +1,38 @@ # - -echo "Hi mom!" +# The following script uses the user and password information +# in file /opt-users/users.txt to to create a database per user, +# set the password for that database and then initialize the postgis +# extensions. +# +# The user file shoudl contain pairs of lines that are the user and password. +# e.g. +# user1 +# passwd1 +# user2 +# passwd2 +# set -e set -u -if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then - echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES" - for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do - echo " Creating user and database '$db'" - echo psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - CREATE USER $db; - CREATE DATABASE $db; - GRANT ALL PRIVILEGES ON DATABASE $db TO $db; -EOSQL +while IFS= read -r dbuser; do + echo "dbuser is $dbuser" + read -r dbpasswd + echo "dbpasswd is $dbpasswd" + echo " Creating user and database '$dbuser'" + + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL1 + CREATE USER $dbuser PASSWORD '$dbpasswd'; + CREATE DATABASE $dbuser; + GRANT ALL PRIVILEGES ON DATABASE $dbuser TO $dbuser; +EOSQL1 + + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" $dbuser <<-EOSQL2 + CREATE EXTENSION postgis; + CREATE EXTENSION postgis_topology; +\dn. +\dt. + GRANT ALL PRIVILEGES ON SCHEMA topology TO $dbuser; +EOSQL2 - done - echo "Multiple databases created" -fi +done < /opt-users/users.txt From 216726fa1fc8fb8c1a3496369ec36b32a5ebe1d0 Mon Sep 17 00:00:00 2001 From: Dirk Grunwald Date: Thu, 27 May 2021 17:58:23 -0600 Subject: [PATCH 4/5] create separate scripts to add users after db created --- README.md | 2 +- users/all-users-add.sh | 11 ++++++++ users/all-users-test.sh | 11 ++++++++ users/single-user-add.sh | 27 +++++++++++++++++++ .../single-user-test.sh | 11 ++++---- 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100755 users/all-users-add.sh create mode 100755 users/all-users-test.sh create mode 100755 users/single-user-add.sh rename test-db-for-gis.sh => users/single-user-test.sh (57%) diff --git a/README.md b/README.md index ef017e9..9a6e543 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ myapp-postgresql_1 | GRANT ## Test it out -The script `./test-db-for-gis.sh` will loop through each user and question run postgres_version() to +The script `./users/all-users-test.sh` will loop through each user and question run postgres_version() to insure that the postgis extensions are installed. It will also create a table that uses a `GEOM` type which would fail if postgis is not setup correctly. diff --git a/users/all-users-add.sh b/users/all-users-add.sh new file mode 100755 index 0000000..33bd0f8 --- /dev/null +++ b/users/all-users-add.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# Test named database for GIS sections +# + +while IFS= read -r dbuser; do + echo "dbuser is $dbuser" + read -r dbpasswd + echo "dbpasswd is $dbpasswd" + ./single-user-add.sh $dbuser $dbpasswd +done < users.txt diff --git a/users/all-users-test.sh b/users/all-users-test.sh new file mode 100755 index 0000000..16379a1 --- /dev/null +++ b/users/all-users-test.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# Test named database for GIS sections +# + +while IFS= read -r dbuser; do + echo "dbuser is $dbuser" + read -r dbpasswd + echo "dbpasswd is $dbpasswd" + ./single-user-test.sh $dbuser $dbpasswd +done < users.txt diff --git a/users/single-user-add.sh b/users/single-user-add.sh new file mode 100755 index 0000000..52ff495 --- /dev/null +++ b/users/single-user-add.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Test named database for GIS sections +# + +export POSTGRES_USER=${POSTGRES_USER:-myapp} +export PGPASSWORD=${PGPASSWORD:-changeme} + +export dbuser=$1 +export dbpasswd=$2 + +echo "dbuser is $dbuser" +echo "dbpasswd is $dbpasswd" + +psql postgresql://$POSTGRES_USER:$PGPASSWORD@localhost < Date: Thu, 27 May 2021 18:07:45 -0600 Subject: [PATCH 5/5] more consistent --- README.md | 150 +++++++++++++++++++++++++--------------- docker-compose.yml | 2 - users/all-users-add.sh | 5 ++ users/all-users-test.sh | 6 ++ users/users.txt | 8 +-- 5 files changed, 110 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 9a6e543..205c511 100644 --- a/README.md +++ b/README.md @@ -25,57 +25,37 @@ passwd2 * Run `docker-compose up` -This should create two database with output similar to: +This should create the default databases (and one called `myapp` with the configuration as is). + +Then, run `users/all-users-add.sh` and it will add databases for individual users. +You can run that multiple times (e.g. if you decide to add a new user). + +The resulting set of databases can be listed by connecting and using `\list`: + + ``` -myapp-postgresql_1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-multiple-postgres-databases.sh -myapp-postgresql_1 | dbuser is db1 -myapp-postgresql_1 | dbpasswd is db1passwd -myapp-postgresql_1 | Creating user and database 'db1' -myapp-postgresql_1 | CREATE ROLE -myapp-postgresql_1 | CREATE DATABASE -myapp-postgresql_1 | GRANT -myapp-postgresql_1 | CREATE EXTENSION -myapp-postgresql_1 | CREATE EXTENSION -myapp-postgresql_1 | List of schemas -myapp-postgresql_1 | Name | Owner -myapp-postgresql_1 | ----------+------- -myapp-postgresql_1 | public | myapp -myapp-postgresql_1 | topology | myapp -myapp-postgresql_1 | (2 rows) -myapp-postgresql_1 | -myapp-postgresql_1 | List of relations -myapp-postgresql_1 | Schema | Name | Type | Owner -myapp-postgresql_1 | ----------+-----------------+-------+------- -myapp-postgresql_1 | public | spatial_ref_sys | table | myapp -myapp-postgresql_1 | topology | layer | table | myapp -myapp-postgresql_1 | topology | topology | table | myapp -myapp-postgresql_1 | (3 rows) -myapp-postgresql_1 | -myapp-postgresql_1 | GRANT -myapp-postgresql_1 | dbuser is db2 -myapp-postgresql_1 | dbpasswd is someother -myapp-postgresql_1 | Creating user and database 'db2' -myapp-postgresql_1 | CREATE ROLE -myapp-postgresql_1 | CREATE DATABASE -myapp-postgresql_1 | GRANT -myapp-postgresql_1 | CREATE EXTENSION -myapp-postgresql_1 | CREATE EXTENSION -myapp-postgresql_1 | List of schemas -myapp-postgresql_1 | Name | Owner -myapp-postgresql_1 | ----------+------- -myapp-postgresql_1 | public | myapp -myapp-postgresql_1 | topology | myapp -myapp-postgresql_1 | (2 rows) -myapp-postgresql_1 | -myapp-postgresql_1 | List of relations -myapp-postgresql_1 | Schema | Name | Type | Owner -myapp-postgresql_1 | ----------+-----------------+-------+------- -myapp-postgresql_1 | public | spatial_ref_sys | table | myapp -myapp-postgresql_1 | topology | layer | table | myapp -myapp-postgresql_1 | topology | topology | table | myapp -myapp-postgresql_1 | (3 rows) -myapp-postgresql_1 | -myapp-postgresql_1 | GRANT +$ psql postgresql://myapp:changeme@localhost + +myapp=# \list + List of databases + Name | Owner | Encoding | Collate | Ctype | Access privileges +------------------+-------+----------+------------+------------+------------------- + alice | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/myapp + + | | | | | myapp=CTc/myapp + + | | | | | db1=CTc/myapp + bob | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/myapp + + | | | | | myapp=CTc/myapp + + | | | | | db2=CTc/myapp + myapp | myapp | UTF8 | en_US.utf8 | en_US.utf8 | + postgres | myapp | UTF8 | en_US.utf8 | en_US.utf8 | + template0 | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =c/myapp + + | | | | | myapp=CTc/myapp + template1 | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =c/myapp + + | | | | | myapp=CTc/myapp + template_postgis | myapp | UTF8 | en_US.utf8 | en_US.utf8 | +(7 rows) + +myapp=# \q ``` ## Test it out @@ -85,18 +65,78 @@ insure that the postgis extensions are installed. It will also create a table th type which would fail if postgis is not setup correctly. ``` -beast-18$ ./test-db-for-gis.sh -dbuser is db1 -dbpasswd is db1passwd +beast-61$ ./all-users-test.sh +Databases are... + List of databases + Name | Owner | Encoding | Collate | Ctype | Access privileges +------------------+-------+----------+------------+------------+------------------- + alice | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/myapp + + | | | | | myapp=CTc/myapp + + | | | | | alice=CTc/myapp + bob | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/myapp + + | | | | | myapp=CTc/myapp + + | | | | | bob=CTc/myapp + myapp | myapp | UTF8 | en_US.utf8 | en_US.utf8 | + postgres | myapp | UTF8 | en_US.utf8 | en_US.utf8 | + template0 | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =c/myapp + + | | | | | myapp=CTc/myapp + template1 | myapp | UTF8 | en_US.utf8 | en_US.utf8 | =c/myapp + + | | | | | myapp=CTc/myapp + template_postgis | myapp | UTF8 | en_US.utf8 | en_US.utf8 | +(7 rows) + +dbuser is alice +dbpasswd is alicePassword +dbuser is alice +dbpasswd is alicePassword + List of schemas + Name | Owner +----------+------- + public | myapp + topology | myapp +(2 rows) + + List of relations + Schema | Name | Type | Owner +----------+-----------------+-------+------- + public | spatial_ref_sys | table | myapp + public | states | table | alice + topology | layer | table | myapp + topology | topology | table | myapp +(4 rows) + postgis_full_version ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="130" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 5.2.0, September 15th, 2018" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.5.0 (Internal)" TOPOLOGY (1 row) -dbuser is db2 -dbpasswd is someother +DROP TABLE +CREATE TABLE +dbuser is bob +dbpasswd is bobPassword +dbuser is bob +dbpasswd is bobPassword + List of schemas + Name | Owner +----------+------- + public | myapp + topology | myapp +(2 rows) + + List of relations + Schema | Name | Type | Owner +----------+-----------------+-------+------- + public | spatial_ref_sys | table | myapp + public | states | table | bob + topology | layer | table | myapp + topology | topology | table | myapp +(4 rows) + postgis_full_version ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="130" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 5.2.0, September 15th, 2018" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.5.0 (Internal)" TOPOLOGY (1 row) + +DROP TABLE +CREATE TABLE ``` diff --git a/docker-compose.yml b/docker-compose.yml index b28317e..94c8a19 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,10 @@ myapp-postgresql: image: postgis/postgis:latest volumes: - - ./script:/docker-entrypoint-initdb.d - ./users:/opt-users - ./dbdata:/var/lib/postgresql/data ports: - "5432:5432" environment: - - POSTGRES_MULTIPLE_DATABASES=db1,db2 - POSTGRES_USER=myapp - POSTGRES_PASSWORD=changeme diff --git a/users/all-users-add.sh b/users/all-users-add.sh index 33bd0f8..8dd4147 100755 --- a/users/all-users-add.sh +++ b/users/all-users-add.sh @@ -9,3 +9,8 @@ while IFS= read -r dbuser; do echo "dbpasswd is $dbpasswd" ./single-user-add.sh $dbuser $dbpasswd done < users.txt + +echo "Databases are..." +psql postgresql://myapp:changeme@localhost <