连接被拒绝 postgres docker [英] connection refused postgres docker

查看:44
本文介绍了连接被拒绝 postgres docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 spring-boot、spring jpa 数据做了一个小应用程序,它连接到一个 dockerized postgres 实例,它工作得很好,即使我尝试通过连接'psql' 到 dockerized postgres 实例它运行良好.问题是当我尝试对我的 spring-boot 应用程序的图像实例进行 dockerize 并尝试将它与 dockerized postegres 实例链接时.我使用的 docker 命令是这个

I made a small application with spring-boot, spring jpa data, that connects to a dockerized postgres instace and it works pretty fine, even if I try to connect via 'psql' to the dockerized postgres instace it works well. The porblem is when I try to dockerize an image's instance of my spring-boot application and I try to link it with the dockerized postegres instance. The docker command I use is this

docker run -it --link mypgcontainerwithpwd:postgres --name postgresclient1 sprinbootjpa

正如我已经提到的,容器 mypgcontainerwithpwd 正在运行并且可以通过 psql 使用本地应用程序访问

As a I already mentioned the container mypgcontainerwithpwd is running and reachable either with a local application either via psql

psql -p 5555 postgres postgres

在 jar 中,我将执行 application.properties 文件,如下所示

in the jar I'm going to execute the application.properties file looks like this

spring.datasource.url=jdbc:postgresql://localhost:5555/postgres
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.generate-ddl=true

在启动阶段会出现一个异常,打印:connection denied localhost->5555

During the starting phase an exception is raised up that prints: connection refused localhost-> 5555

构建实例的dockerfile长这样

The dockerfile that builds the instace looks like this

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD ./SpringJPA-PostgreSQ-0.0.1.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

我是 docker 新手,我没有找到任何可以解决这个问题的方法,我正在使用 unix 容器在 Windows 10 上运行 docker.

I'm new to docker and I didn't find anything to fix the issue, I'm running docker on windows 10 with unix containers.

谢谢大家.

推荐答案

在您的属性文件中,您声明 postgres 与您的 Spring Boot 应用程序 (localhost) 在同一个容器中运行,但事实并非如此,因为它运行在不同的容器.

In your property file you are stating that postgres is running in the same container as your Spring Boot application (localhost) which is not true as it is running in a different container.

用这个替换你的财产:

spring.datasource.url=jdbc:postgresql://postgres:5555/postgres

您也可以指向 docker 网桥 IP,通常为 172.17.0.1.

You could also point to the docker bridge ip which usually is 172.17.0.1.

这篇关于连接被拒绝 postgres docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆