GitHub - theplant/docker-postgresql-multiple-databases: Using multiple databases with the official PostgreSQL Docker image

The official recommendation 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

You still need to pass the POSTGRES_MULTIPLE_DATABASES environment variable to the container:

myapp-postgresql:
    image: public.ecr.aws/theplant/postgresmd:13
    environment:
        - POSTGRES_MULTIPLE_DATABASES=db1,db2
        - POSTGRES_USER=myapp
        - POSTGRES_PASSWORD=

Push image

Please assume AWS IAM developer role before push image

[alias.main-developer]
arn = "arn:aws:iam::562055475000:role/developer"
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/theplant

Non-standard database names

If you need to use non-standard database names (hyphens, uppercase letters etc), quote them in POSTGRES_MULTIPLE_DATABASES:

    environment:
        - POSTGRES_MULTIPLE_DATABASES="test-db-1","test-db-2"