[英]Spring Boot with Postgres application not working on Docker. Error: PSQLException: Connection to 127.0.0.1:5432 refused.
When trying to build and run my containers using Docker 'docker-compose up' command I keep getting this error:当尝试使用 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.
I have googled for solutions and tried different things but nothing works.我在谷歌上搜索了解决方案并尝试了不同的方法,但没有任何效果。 My docker-compose.yaml file:
我的 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
My Dockerfile:我的 Dockerfile:
FROM openjdk:11
ADD target/visma-meeting-app-withdb-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
My application.properties file:我的 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
Maybe anyone has run into this problem before and knows the solution?也许有人以前遇到过这个问题并且知道解决方案?
Try connecting to localhost port 5432.尝试连接到本地主机端口 5432。
If the issue persists then check if PostgreSQL is listening to TCP/IP connections.如果问题仍然存在,请检查 PostgreSQL 是否正在侦听 TCP/IP 连接。
" sudo lsof -n -u postgres |grep LISTEN " will show the TCP/IP addresses and ports PostgreSQL is listening on. “ sudo lsof -n -u postgres |grep LISTEN ” 将显示正在侦听的 TCP/IP 地址和端口 PostgreSQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.