简体   繁体   English

Spring 使用 Postgres 应用程序启动时无法在 Docker 上运行。错误:PSQLException:拒绝连接到 127.0.0.1:5432。

[英]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.

相关问题 与 127.0.0.1:5432 的连接被拒绝。 检查主机名和端口是否正确以及 postmaster 是否接受 TCP/IP 连接 - 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 + Spring 引导 + Postgres-org.postgresql.util.PSQLException:连接尝试失败 - Docker + Spring Boot + Postgres-org.postgresql.util.PSQLException: The connection attempt failed 连接拒绝尝试连接 spring 在 docker 启动应用程序 - Connection refused trying to connect spring boot application in docker 连接被拒绝:访问在Docker容器中运行的Spring Boot应用程序 - Connection refused: accessing a spring boot application running in docker container docker镜像中的spring boot应用程序错误连接到localhost:5433被拒绝 - spring boot app in docker image error Connection to localhost:5433 refused finishConnect(..) 失败:连接被拒绝:localhost/127.0.0.1,错误:Webflux、Webclient、Spring 启动、java - finishConnect(..) failed: Connection refused: localhost/127.0.0.1 , error: Webflux, Webclient, Spring boot, java Cloud Foundry Spring Boot应用程序中的连接被拒绝错误 - Connection Refused Error in Cloud Foundry Spring Boot application Spring 引导 MySQL Docker ConnectException:连接被拒绝 - Spring Boot MySQL Docker ConnectException: Connection refused 连接到<hostname> :5432 拒绝 - Connection to <hostname>:5432 refused 使用docker-compose启动dockerized Spring Boot和MariaDb时出现连接拒绝错误 - Connection refused error when starting dockerized Spring Boot and MariaDb with docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM