Docker Community Forums

Share and learn in the Docker community.

Postgresql container with multiple users and dbs

Greetings,

I am writing a compose file which has two apps (app1,app2) containers and one postgresql container. The requirement is to, create multiple postgresql db’s / users so that each app container use it’s own db and role. I wrote the following, but it only creates one set (app1db & app1user). Please help on how to achieve this.

indent preformatted text by 4 spaces
  - 'POSTGRES_USER=app1user'
  - 'POSTGRES_USER=app2user'
  # CHANGE THE PASSWORD!
  - 'POSTGRES_PASSWORD=password'
  - 'POSTGRES_DB=app1db'
  - 'POSTGRES_DB=app2db'
  - 'POSTGRES_ENCODING=UNICODE'
  - 'POSTGRES_COLLATE=C'
  - 'POSTGRES_COLLATE_TYPE=C'

Thank you in advance
-Sha

Check out this repo: Docker Hub