本文介绍了docker和docker-compose中的多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,该项目由两个使用8个postgres数据库的主要Java应用程序组成,所以docker-compose中是否可以构建8个不同的数据库,以便每个数据库具有不同的所有者和密码?我什至可以在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,
Tom

Tnx,Tom

推荐答案

根据此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

EDIT

要创建多个数据库,可以使用以下脚本:

To create multiple Databases you could use the following script:

这建议您必须克隆上述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中的多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:45