docker 和 docker-compose 中的多个数据库 [英] Multiple databases in docker and docker-compose
问题描述
我有一个项目由两个主要的 Java 应用程序组成,这些应用程序使用八个 postgres 数据库,那么 docker-compose 有没有办法构建八个不同的数据库,以便每个数据库都有不同的所有者和密码?我什至可以在 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?
示例:
services:
postgresql:
build: db/.
ports:
- "5432:5432"
environment:
- POSTGRES_DB=database1
- POSTGRES_USER=database1
- POSTGRES_PASSWORD=database1
我知道我可以将所有 .sql 文件放在 docker-entrypoint-initdb.d 中,postgres 会自动生成它们,但是我如何声明哪些 .sql 文件放在哪个数据库中?
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,汤姆
推荐答案
根据这个 Github 问题可能可以通过使用 bash 脚本来实现多个数据库,您必须在 Dockerfile 中传递这些脚本
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
编辑:
要创建多个数据库,您可以使用以下脚本:
To create multiple Databases you could use the following script:
https://github.com/mrts/docker-postgresql-multiple-databases
或
https://github.com/MartinKaburu/docker-postgresql-multiple-databases
这表明您必须克隆上述 git repos 之一并将其作为卷安装到:/docker-entrypoint-initdb.d 然后您将能够使用以下方法传递多个数据库名称:POSTGRES_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
这篇关于docker 和 docker-compose 中的多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!