Spring Boot with Postgres application not working on Docker. Error: PSQLException: Connection to 127.0.0.1:5432 refused.
Spring Boot with Postgres application not working on Docker. Error: PSQLException: Connection to 127.0.0.1:5432 refused.
尝试使用 Docker 'docker-compose up' 命令构建和 运行 我的容器时,我不断收到此错误:
org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
我在谷歌上搜索了解决方案并尝试了不同的方法,但没有任何效果。
我的 docker-compose.yaml 文件:
My docker-compose.yaml file:
version: '3.8'
services:
app:
container_name: docker-meetings
image: docker_meetings
build: ./
ports:
- "8080:8080"
expose:
- "8080"
depends_on:
- postgresqldb
postgresqldb:
image: postgres
ports:
- "5432:5432"
expose:
- "5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=db
- POSTGRES_DB=meetingsdb
我的Docker文件:
FROM openjdk:11
ADD target/visma-meeting-app-withdb-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
我的 application.properties 文件:
spring.datasource.url=jdbc:postgresql://postgresqldb:5432/meetingsdb?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&stringtype=unspecified
spring.datasource.username=postgres
spring.datasource.password=db
也许有人 运行 遇到过这个问题并且知道解决方案?
尝试连接到本地主机端口 5432。
如果问题仍然存在,请检查 PostgreSQL 是否正在侦听 TCP/IP 个连接。
" sudo lsof -n -u postgres |grep LISTEN " 将显示 TCP/IP PostgreSQL 正在侦听的地址和端口。
尝试使用 Docker 'docker-compose up' 命令构建和 运行 我的容器时,我不断收到此错误:
org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
我在谷歌上搜索了解决方案并尝试了不同的方法,但没有任何效果。 我的 docker-compose.yaml 文件:
My docker-compose.yaml file:
version: '3.8'
services:
app:
container_name: docker-meetings
image: docker_meetings
build: ./
ports:
- "8080:8080"
expose:
- "8080"
depends_on:
- postgresqldb
postgresqldb:
image: postgres
ports:
- "5432:5432"
expose:
- "5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=db
- POSTGRES_DB=meetingsdb
我的Docker文件:
FROM openjdk:11
ADD target/visma-meeting-app-withdb-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
我的 application.properties 文件:
spring.datasource.url=jdbc:postgresql://postgresqldb:5432/meetingsdb?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&stringtype=unspecified
spring.datasource.username=postgres
spring.datasource.password=db
也许有人 运行 遇到过这个问题并且知道解决方案?
尝试连接到本地主机端口 5432。
如果问题仍然存在,请检查 PostgreSQL 是否正在侦听 TCP/IP 个连接。
" sudo lsof -n -u postgres |grep LISTEN " 将显示 TCP/IP PostgreSQL 正在侦听的地址和端口。