两个docker容器之间的连接

两个docker容器之间的连接,docker,containers,Docker,Containers,在这个问题中,我参考了以下问题的答案:。我有两个docker容器。其中一个是我的数据库,另一个是詹金斯服务器。后者已创建并正在运行。我的数据库的docker容器创建如下: docker run -d --name postgres -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -p 127.0.0.1:5432:5432 postgres:10.4-alpine 然后,我通过 docke

在这个问题中,我参考了以下问题的答案:。我有两个docker容器。其中一个是我的数据库,另一个是詹金斯服务器。后者已创建并正在运行。我的数据库的docker容器创建如下:

docker run -d --name postgres -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -p 127.0.0.1:5432:5432  postgres:10.4-alpine
然后,我通过

docker network create --driver=bridge postgres_jenkins_network
并将这两个容器都放在这个网络中

docker network connect postgres_jenkins_network postgres
docker network connect postgres_jenkins_network jenkins
不幸的是,我的jenkins无法连接到我的postgres数据库,因为我遇到以下错误:

org.postgresql.util.PSQLException: Connection to localhost:5432 refused
jenkins测试的我的应用程序具有以下应用程序属性和yml数据:

应用程序属性

application.yml

看起来,我的应用程序无法访问我的数据库,但我不知道为什么会这样

谢谢你的帮助
Matthias

据我所知,您必须在application.yml文件的url中使用postgres而不是localhost:jdbc:postgresql://postgres:5432/postgres 因为您想连接到postgres数据库服务器,该服务器在名为postgres的容器中运行。

可能与
spring.profiles.active=dev
  spring:
  profiles: dev

  datasource:
    platform: postgres
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres
    username: user
    password: password

server:
  servlet:
    context-path: /mep
  port: 9000