Reputation: 2483
I have to configure Redis with Socketio in my Laravel application. However, what ever I have tried so far, I get the same error:
Connection refused [tcp://127.0.0.1:6379] i
I can go to the container with docker exec -it id sh and when I ping the server I get the PONG message. Client is already 'predis' in my database.php file and package also installed.
.env
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
docker-compose.yml
version: "2"
services:
api:
build: .
ports:
- 9000:9000
volumes:
- .:/app
- /app/vendor
depends_on:
- postgres
- redis
environment:
DATABASE_URL: postgres://xx@postgres/xx
postgres:
image: postgres:latest
environment:
POSTGRES_USER: xx
POSTGRES_DB: xx
POSTGRES_PASSWORD: xx
volumes:
- .Data:/var/lib/postgresql/data
ports:
- 3306:5432
redis:
build: ./Redis/
ports:
- 6003:6379
volumes:
- ../RedisData/data:/data
command: redis-server --appendonly yes
Dockerfile (redis)
FROM redis:alpine
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
Upvotes: 9
Views: 12881
Reputation: 5422
If you have defined networks
in your docker-compose.yml
also make sure that all services (both your Laravel as well as redis) are in the same network.
networks:
internal:
driver: bridge
Then:
app:
[cut]
networks:
- internal
redis:
image: redis:alpine
volumes:
- ./docker/volumes/redis:/data
ports:
- "6379:6379"
networks:
- internal
So that caching can talk to your app.
Upvotes: 0
Reputation: 3155
Had Same issue...
Also updated following in redis.conf
bind 127.0.0.1
To
bind redis
as redis is the existing host now
Upvotes: 0
Reputation: 181
Set your REDIS_HOST to redis like this REDIS_HOST=redis. The reason is that you already built your docker file and specified redis as the name of your redis service
Upvotes: 1
Reputation: 22691
The error is saying it can connect to 127.0.0.1
on port 6379
. So make sure the host and port is ok:
host 127.0.0.1 is ok: this work if you run the php on the same host than redis, or if you run php on Docker host machine, but in this case, the port will be 6003
port 6379 is ok: host is not good, you must specify the Docker container hostname: redis
make sure configuration cache is ok
Upvotes: 13