# Postgres connection refused problem

**URL:** <https://forums.docker.com/t/postgres-connection-refused-problem/91152>\
**Category:** Compose\
**Tags:** dockerhub, docker, build\
**Created:** [March 25, 2020, 9:10am UTC](https://forums.docker.com/t/postgres-connection-refused-problem/91152 "2020-03-25T09:10:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![commomegasator](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@commomegasator](https://forums.docker.com/u/commomegasator)\
**Post date:** [March 25, 2020, 9:10am UTC](https://forums.docker.com/t/postgres-connection-refused-problem/91152/1 "2020-03-25T09:10:21Z")

</div>

Hi there!  
I need help. I am using Redis + PostgreSQL in my Spring Boot app(java). I have created Dockerfile and docker-compose.yml. And application image crashes and gives me postgres connection refused error. Postgres image and also Redis image is working well without it. Please help me.

Dockerfile:  
FROM openjdk:8-jdk-alpine

VOLUME /tmp

EXPOSE 3000  
EXPOSE 3001  
EXPOSE 3002

RUN mkdir -p /versatile/  
RUN mkdir -p /versatile/logs/  
ADD target/versatile-development.jar versatile/versatile-development.jar

ENV POSTGRES\_DB versatile  
ENV POSTGRES\_USER postgres  
ENV POSTGRES\_PASSWORD postgres  
ENV POSTGRES\_PORT 5432

ENTRYPOINT [“java”, “-jar”, “versatile/versatile-development.jar”]

docker-compose.yml:

version: “3”

services:  
versatile-development:  
container\_name: versatile  
build:  
context: .  
dockerfile: Dockerfile  
environment:  
- POSTGRES\_HOST=postgresql  
- DB\_CONNECTION=pgsql  
- DB\_HOST=postgresql  
- DB\_PORT=5431  
- DB\_DATABASE=versatile  
- DB\_USERNAME=postgres  
- DB\_PASSWORD=postgres  
- REDIS\_HOST=redis  
- REDIS\_PORT=6379  
ports:  
- 3000:8081  
links:  
- postgresql  
- redis

postgresql:  
image: postgres:11.7  
network\_mode: bridge  
container\_name: postgresql  
environment:  
- POSTGRES\_DB=versatile  
- POSTGRES\_USER=postgres  
- POSTGRES\_PASSWORD=postgres  
volumes:  
- postgres-data:/var/lib/postgresql/data  
ports:  
- 3001:5432

redis:  
image: redis:latest  
container\_name: redis  
ports:  
- 3002:6379

volumes:  
postgres-data:
