-1

in this question, I refer to the answer to the following question: here.I have two docker container. In one I have my database and in the other a jenkins server. The latter was already created and is running. My docker container for my database is created as follows:

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

Then I created a nework via

docker network create --driver=bridge postgres_jenkins_network

and put both container in this network with

docker network connect postgres_jenkins_network postgres
docker network connect postgres_jenkins_network jenkins

Unfortunately, my jenkins is not able to connect to my postgres database, since I get the following error:

org.postgresql.util.PSQLException: Connection to localhost:5432 refused

My Application which is tested by jenkins has the following application properties and yml data:

application.properties

spring.profiles.active=dev

application.yml

  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

It seems, that my application get no access to my database but I have no idea why this is the case.

Thanks for any help Matthias

Community
  • 1
  • 1
  • Possible duplicate of [nginx docker container: 502 bad gateway response](https://stackoverflow.com/questions/38346847/nginx-docker-container-502-bad-gateway-response) – Artemij Rodionov Sep 17 '18 at 22:08

1 Answers1

2

As far as I can tell, you have to use postgres instead of localhost in the url in your application.yml file: jdbc:postgresql://postgres:5432/postgres Because you want to connect to your postgres database server which runs in the container with the name postgres.

Florian Fankhauser
  • 3,615
  • 2
  • 26
  • 30