I try to up several postgres databases by writing docker-compose file and create database when container is up. The problem is - that database is not created
I do not understand why it doesn't create. But if i try to up only one postgres it works. What i missed?
works well:
services:
tenant_first:
image: postgres
restart: always
volumes:
- pgdata:/var/lib/postgresql/data/
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=tenant_first
ports:
- 50005:5432
Doesn't work (not create database if more than one recording)
services:
tenant_first:
image: postgres
restart: always
volumes:
- pgdata:/var/lib/postgresql/data/
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=tenant_first
ports:
- 50005:5432
tenant_second:
image: postgres
restart: always
volumes:
- pgdata:/var/lib/postgresql/data/
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=tenant_second
ports:
- 50008:5432
I did it works adding volumes
volumes:
pgdata:
pgdata2: