Docker-compose up springboot + postgres Connection refused

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Docker-compose up springboot + postgres Connection refused



I create an sample java project with springboot data and postgres. I started to make my docker-compose but i can't link my database to my application...



I have this error


web_1 | org.postgresql.util.PSQLException: Connection to localhost:5438 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.



On my application ressource


server:
port: 4000

spring:
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5438/acronym
username: acronym
password: acronym1234
driver-class-name: org.postgresql.Driver
jpa:
database: POSTGRESQL
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: create



and my docker compose file


version: '3.3'
services:
web:
image: acronym:latest
ports:
- 4000:4000
networks:
- webnet
depends_on:
- db
db:
image: postgres:9.6
restart: always
environment:
- POSTGRES_USER=acronym
- POSTGRES_PASSWORD=acronym1234
- POSTGRES_DB=acronym
-PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- /var/lib/postgresql/data
ports:
- '5438:5432'
volumes:
db:
networks:
webnet:



I saw a lot of topic and the solution is to replace localhost to db but that doesn't work



How can i link my database to my app with docker-compose ?




1 Answer
1



Use jdbc:postgresql://db:5438/acronym as connection url.


jdbc:postgresql://db:5438/acronym



The service is exposed under its name by default (in that case db).


db





Thx you to reply ! Yes I tried to replace localhost to db on my applocation resource, I have the same issue :(
– nakata77fr
2 days ago





Ok i try again with db and the port 5432 ...and it work !! THX YOU
– nakata77fr
yesterday







You mapped the ports, inside the docker network (webnet) it is available under the port 5438 and on the localhost over 5432. ports: - '5438:5432' You could use the same port to avoid confusion => ports: - '5438:5438'
– Daniel Prinz
yesterday


ports: - '5438:5432'


ports: - '5438:5438'






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS