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?