I have a docker compose with one container PostgreSQL and another one with my App. I need to restore two databases into the PostgreSQL and then make the App start.
Currently I have tried this docker compose:
version: "3.7"
services:
dataspace_postgres:
container_name: custompostgres
platform: linux/amd64
build:
context: ./
dockerfile: Dockerfile.CustomPostgres
networks:
- dataspace
environment:
PGUSER: postgres
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- 5434:5432
volumes:
- disk-postgres:/var/lib/postgresql/data
- ./dumps/psql/managementreporting.sql:/managementreporting.sql
- ./dumps/psql/idams_new.sql:/idams_new.sql
- ./dumps/init.sh:/docker-entrypoint-initdb.d/init.sh
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U postgres -d managementreporing'"]
interval: 10s
timeout: 120s
retries: 10
dataspace_consolidatedreportingunit:
container_name: consolidatedreportingunit
platform: linux/amd64
build:
context: ./
dockerfile: Dockerfile.ReportingTool
networks:
- dataspace
ports:
- 8080:80
- 8081:443
depends_on:
dataspace_postgres:
condition: service_healthy
networks:
dataspace:
driver: bridge
volumes:
disk-postgres:
driver: local
And my init.sh file:
pg_restore -v -c -d managementreporting managementreporting.sql
pg_restore -v -c -d idams_new idams_new.sql
Currently on startup it fails with the following error no matter what i tried:
pg_restore: connecting to database for restore custompostgres
| 2023-09-29 14:27:03.007 UTC [64] FATAL: database "managementreporting" does not exist custompostgres | pg_restore: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "managementreporting" does not exist custompostgres exited with code 1
For me the only way to restore the databases is to mount them directly into /docker-entrypoint-initdb.d/ (for dumps) but then I have no way to make the other container wait the postgesql to finish the restore.
Any ideas?
Dockerfile.CustomPostgreslook like? Isinit.shthe entrypoint?