Answer the question
In order to leave comments, you need to log in
How to connect to Redis with php via docker?
I use docker-compose, I connect redis like this
redis:
restart: always
image: redis
depends_on:
- vesta
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
$redis = new Redis();
$redis->connect('127.0.0.1');
echo $redis->ping();
Fatal error: Uncaught RedisException: Redis server went away
Answer the question
In order to leave comments, you need to log in
What does it docker-compose ps
show for you - are all containers running?
192.168.0.1This is the ip of the host, there is no Redis there.
127.0.0.1This is a localhost, there is no Redis there.
0.0.0.0This is generally invalid ip.
redisBut by name it should work. You need to figure out the network name and do
docker network inspect %name%
to see Redis' ip - it should work for sure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question