Docker Community Forums

Share and learn in the Docker community.

Postgres connection refused problem

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: