我的Spring Boot应用程序和Postgres数据库之间的内部连接工作得很好,但当我想通过init_database ase.sh和pg_Restore连接到数据库时,我会得到pg_restore: error: connection to server at "db" (192.168.224.2), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
。在这个.sh脚本中,我使用的主机和端口与Application.Properties中的主机和端口相同(正如我前面所说的,连接在这里工作得很好)。
我只想从我的Docker容器中的init_database ase.sh执行pg_Restore。
Docker-compose.yml
services:
db:
container_name: db
hostname: db
image: postgres:14-alpine
command: -c 'max_connections=250'
ports:
- "5430:5432"
environment:
POSTGRES_DB: endlessblow_db
POSTGRES_USER: kuba
POSTGRES_PASSWORD: pass
volumes:
- ./init.dump:/init.dump
- ./init_database.sh:/docker-entrypoint-initdb.d/init_database.sh
restart: always
app:
container_name: app
image: 'endlessblow-server:latest'
build: ./
ports:
- "8000:8080"
depends_on:
- db
Init_database ase.sh
# !/bin/sh
pg_restore --no-privileges --no-owner -h db -p 5432 -U kuba -d endlessblow_db init.dump
Application.properties
spring.datasource.jdbc-url=jdbc:postgresql://db:5432/endlessblow_db
spring.datasource.url=jdbc:postgresql://db:5432/endlessblow_db
spring.datasource.username=kuba
spring.datasource.password=pass
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.platform=postgres
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
如何解决这个问题?谢谢!
1条答案
按热度按时间c8ib6hqw1#
在服务app的配置中,尝试如下操作:
如果没有链接,码头网络将隔离容器,而不会显式地将它们暴露给另一个容器。