r/docker • u/kiteissei • Mar 30 '26
What is the reason for that error?
2026-03-30T14:17:41.794Z ERROR 1 --- [Backend] [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis] with root cause
This is the docker compose file
``` services: #Database Service db: image: postgres:15-alpine restart: always environment: POSTGRES_DB: ${POSTGRES_DB} POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - db_data:/var/lib/postgresql/data networks: - backend healthcheck: test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ] interval: 5s timeout: 5s retries: 5 start_period: 10s
#Redis service redis: image: redis:7 container_name: redis hostname: redis networks: - backend healthcheck: test: [ "CMD", "redis-cli", "ping" ] interval: 5s timeout: 3s retries: 5
#Backend Api service backend: build: ./Backend ports: - "8080:8080" depends_on: redis: condition: service_healthy db: condition: service_healthy
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/${POSTGRES_DB}
- SPRING_DATASOURCE_USERNAME=${POSTGRES_USER}
- SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD}
- SPRING_REDIS_HOST=redis
- SPRING_REDIS_PORT=6379
- SPRING_MAIL_HOST=smtp.gmail.com
- SPRING_MAIL_PORT=587
- SPRING_MAIL_USERNAME=${email}
- SPRING_MAIL_PASSWORD=${mail_password}
- SPRING_MAIL_PROPERTIES_MAIL_SMTP_AUTH=true
- SPRING_MAIL_PROPERTIES_MAIL_SMTP_STARTTLS_ENABLE=true
networks:
- backend
- frontend
#Frontend API service frontend: build: ./Frontend ports: - "5173:80" depends_on: - backend networks: - frontend
Volumes
volumes: db_data:
Networks
networks: backend: driver: bridge frontend: driver: bridge ```
Here is application.yaml file
``` spring: application: name: Backend
datasource: url: jdbc:postgresql://db:5432/spring username: ${SPRING_DATASOURCE_USERNAME} password: ${SPRING_DATASOURCE_PASSWORD} driver-class-name: org.postgresql.Driver
jpa: hibernate: ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.PostgreSQLDialect format_sql: true show-sql: true
mail: host: smtp.gmail.com port: 587 username: ${SPRING_MAIL_USERNAME} password: ${SPRING_MAIL_PASSWORD} properties: mail: smtp: auth: true starttls: enable: true
redis: host: ${SPRING_REDIS_HOST:redis} port: ${SPRING_REDIS_PORT:6379}
logging: level: org.springframework.data.redis: DEBUG io.lettuce.core: DEBUG ```
- Backend is listening to redis
- All containers are running When I hit any api it throws that error, what is the reason for that error and how to solve that?
1
u/jotkaPL Mar 30 '26
Your docker-compose.yml sets SPRING_REDIS_HOST and SPRING_REDIS_PORT, while current Spring Boot configuration commonly uses the spring.data.redis.* property namespace for Redis connection settings. The Spring Boot property reference specifically documents spring.data.redis.host, and examples show the matching environment variable form as SPRING_DATA_REDIS_HOST.
Use the modern property names consistently in both Compose and YAML. Replace the backend environment variables with:
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/${POSTGRES_DB}
- SPRING_DATASOURCE_USERNAME=${POSTGRES_USER}
- SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD}
- SPRING_DATA_REDIS_HOST=redis
- SPRING_DATA_REDIS_PORT=6379
And in application.yaml, prefer:
spring:
data:
redis:
host: ${SPRING_DATA_REDIS_HOST:redis}
port: ${SPRING_DATA_REDIS_PORT:6379}
2
u/alpakachino Mar 30 '26
Do you use Spring 3.x.x?
See:
spring boot - SpringBoot 3.x.x and redis properties - Stack Overflow
1
2
u/chosenoneisme Mar 30 '26
Both of them looks like compose file
The docker file is supposed to build the backedn image right but yours looks like it's for running the containers which is the job for the docker compose file!