Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

postgresql - Multiple databases in docker and docker-compose

I have a project consisting of two main java apps that use eight postgres databases, so is there a way in docker-compose to build eight different databases so that each one has a different owner and password? Can I even do that in docker-compose?

example:

services:
    postgresql:
        build: db/.
        ports:
            - "5432:5432"
        environment:
          - POSTGRES_DB=database1
          - POSTGRES_USER=database1
          - POSTGRES_PASSWORD=database1

I know I can put all the .sql files in the docker-entrypoint-initdb.d and postgres will make them automatically, but how do I declare what .sql file goes in what database?

Tnx, Tom

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to this Github issue might be possible to achieve multiple databases by using bash scripts which you will have to pass in your Dockerfile

EDIT:

To create multiple Databases you could use the following script:

https://github.com/mrts/docker-postgresql-multiple-databases

or

https://github.com/MartinKaburu/docker-postgresql-multiple-databases

Which suggest that you have to clone one of the above git repos and mount it as a volume to: /docker-entrypoint-initdb.d then you would be able to pass multiple database names by using: POSTGRES_MULTIPLE_DATABASES variable


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...