0

I have an App built on Laravel. I'm using Laradock and I'm trying to use Redis container, but I have a problem with connection.

With the command:

docker inspect laradock_redis_1

I can see that: "IPAddress": "172.22.0.2",

By In my frontend I'm trying to connect to Redis with ioredis:

import Redis from 'ioredis';
const redis = new Redis({
                 port: 6379,
                 host: 172.22.0.2,
                 password: "password"
               });
redis.on('pmessage', function(subscribed, channel, message) {
...
})

But I can't connect because I get this error:

[ioredis] Unhandled error event: Error: connect ETIMEDOUT

I'm trying also with change ip and port like:

port: 6379,
host: 127.0.0.1,

Or changing the port on docker-compose with 1111 but it doesn't work yet. What am I doing wrong?

LorenzoBerti
  • 6,704
  • 8
  • 47
  • 89

1 Answers1

0

Instead of using the container ip address you can the name of the container or if you are using docker-compose.yml you can use the name of the service instead of ip address. So something along these lines would work:

const redis = new Redis({
                 port: 6379,
                 host: laradock_redis_1
               });
Nikola Gavric
  • 3,507
  • 1
  • 8
  • 16
  • thankyou for answer, but it return error. [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND and then [ioredis] Unhandled error event: Error: connect ETIMEDOUT – LorenzoBerti Jan 28 '19 at 15:10