Multiple databases in docker and docker-compose
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
Usually when I need more than one database in a docker project it's a test database. I find it easier to simply spin up a second docker container, without worrying about scripts or volume separation.
The main trick is to not conflict the default ports (e.g. 5432 for postgres) and you're good to go.
Then docker-compose
can be something as simple as this:
version: '3.0'
services:
db:
image: postgres
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
ports:
- ${POSTGRES_DEV_PORT}:5432
volumes:
- app-volume:/var/lib/postgresql/data
db-test:
image: postgres
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
ports:
- ${POSTGRES_TEST_PORT}:5432
# Notice I don't even use a volume here since I don't care to persist test data between runs
volumes:
app-volume: #