Basically I have a database feedback created in postgres and for creating the table I used flyway. The table script is located in resources/db.migration. Postgres is configured using spring properties. But I want to run my application using docker compose and when I run it I get this error that says
postgres-db | Message : Connection to localhost:5333 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Docker compose configuration
version: "3.8"
networks:
app:
driver: bridge
services:
postgres:
image: postgres:16.0-alpine
container_name: postgres-db
volumes:
- ./postgres-data:/var/lib/postgresql/data
- ./initdb:/docker-entrypoint-initdb.d
ports:
- 5333:5432
environment:
- POSTGRES_DB=feedback_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=1
healthcheck:
test: \["CMD", "pg_isready", "-q", "-U", "postgres", "-d", "feedback_db"\]
interval: 5s
timeout: 1s
retries: 5
networks:
- app
flyway:
image: flyway/flyway
command: -url=jdbc:postgresql://postgres:5432/feedback_db -schemas=public -user=postgres -password=1 migrate
volumes:
- ./src/main/resources/db/migration:/flyway/sql
depends_on:
postgres:
condition: service_healthy
networks:
- app
feedback-service:
build: .
container_name: rugid-feedback-service
ports:
- 8082:8080
depends_on:
postgres:
condition: service_healthy
environment:
- SPRING_FLYWAY_URL=jdbc:postgresql://postgres:5432/feedback_db
- SPRING_FLYWAY_USER=postgres
- SPRING_FLYWAY_PASSWORD=1
- SPRING_R2DBC_URL=r2dbc:postgresql://postgres:5432/feedback_db
- SPRING_R2DBC_USERNAME=postgres
- SPRING_R2DBC_PASSWORD=1
networks:
- app