我有一个与一个容器PostgreSQL和另一个与我的应用程序组成的 docker .我需要将两个数据库恢复到PostgreSQL中,然后启动应用程序.
目前,我已经try 了这个对接器组合:
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
和我的init.sh文件:
pg_restore -v -c -d managementreporting managementreporting.sql
pg_restore -v -c -d idams_new idams_new.sql
目前在启动时,无论我try 什么,它都会失败,并出现以下错误:
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
对我来说,恢复数据库的唯一方法是将它们直接挂载到/docker-入口点-initdb.d/中(对于转储),但是我无法让另一个容器等待postgesql来完成恢复.
有什么主意吗?