Skip to content

Conversation

emanuele-scarsella
Copy link

This pull request adds the ability to define a custom username and password for each database.

The original script used the database name as the name for the user with access privileges to it and didn't allowed for any password, this is kept as the default behavior to ensure backwards compatibility, but it is now possible to define a different username and password for each database by adding the POSTGRES_USER_<uppercase database name>
and POSTGRES_PASSWORD_<uppercase database name> environment variables as shown in the following example:

    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:
            - POSTGRES_USER_DB1: myapp_db1
            - POSTGRES_PASSWORD_DB1:
            - POSTGRES_USER_DB2: myapp_db2
            - POSTGRES_PASSWORD_DB2:


As an added feature the code now checks if a user/database already exists before trying to create it fixing issue #4 and it also now include the --dbname variable in the psql commands fixing issue #29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant