I have an app running in docker and also have redis as a service. Redis is building successfully and i can see the service running in same container but the app is unable to connect it.
Docker service running
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
48007b9bc91f redis:latest "docker-entrypoint.s…" 3 seconds ago Up 1 second (health: starting) 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp symfony_redis
redis connection error from symfony application using snc-redis package
Connection refused [tcp://0.0.0.0:6379]
docker-compose.yaml
version: '3.7'
services:
redis:
build:
context: .docker/redis
dockerfile: Dockerfile
image: redis:7.2.4
container_name: symfony_redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 30s
timeout: 10s
retries: 5
networks:
- app-network
api:
build:
context: ../../
dockerfile: tazman-backend/symfony/.docker/api/Dockerfile
container_name: symfony_api
volumes:
- ../../components:/var/www/html/components:rw,cached
- ../:/var/www/html/backend:rw,cached
ports:
- "9000:9000"
environment:
APP_ENV: dev
depends_on:
- redis
2
Answers
In your code, make sure to use
redis
for the domain. For instancehttp://redis/
.redis
andapi
containers should utilize the same network, you have specified custom network for redis (it would depend on your requirements/necessities, but in most common cases you can run without specifying any custom network, it would use yourdefault
network)so you need either to remove custom network from your
redis
container, or add the samenetworks
part to yourapi
container’s description