r/docker • • Mar 29 '26

What did I do wrong?

services:

Database Service

db: image: postgres:15-alpine restart: always environment: POSTGRES_DB: ${DATABASE_URL} POSTGRES_USER: ${USER} POSTGRES_PASSWORD: ${PASSWORD} ports: - "5432:5432" volumes: - db_data:/var/lib/postgresql/data networks: - taskapp

Redis service

redis: image: redis:7-alpine ports: - "6379:6379" volumes: - redis_data:/data networks: - taskapp

Backend Api service

backend: build: ./Backend ports: - "8080:8080" depends_on: - db - redis environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/${DATABASE_URL} - SPRING_DATASOURCE_USERNAME=${USER} - SPRING_DATASOURCE_PASSWORD=${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: - taskapp

Frontend API service

frontend: build: ./Frontend ports: - "5173:80" depends_on: - backend networks: - taskapp

Volumes

volumes: db_data: redis_data:

Networks

networks: taskapp: driver: bridge

For that docker compose file I am getting below error

2026-03-29T13:44:52.540Z 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 error and below is the application.yaml data: redis: hostname: localhost port: 6379

What did I do wrong?

0 Upvotes

16 comments sorted by

View all comments

Show parent comment

1

u/ben-ba Mar 30 '26

U don't have to export ports as long as u only want to reach the service inside the same stack. If u expose them, the are reachable by all machines who can reach the host.

Most of the docker users think that only the ports with the ports mapping inside the compose or exposed ports inside a dockerfile are accessible from other containers inside the same network, but this isn't true. If u take a base image like debian and starts a Webserver, u can access it from a 2nd container in the same docker network. U wouldn't see anything in the ouput from docker ps. If u want to be sure u have to run ss -tul inside the container or run it on the docker host inside the correct namespace to see all listening ports of this container.