我有一个基于Laravel的应用程序。我正在使用Laradock,我正在尝试使用Redis容器,但我在连接方面遇到了问题。
有命令:
docker inspect laradock_redis_1我可以看到:"IPAddress":"172.22.0.2",
在我的前面,我正试图用ioredis连接Redis:
import Redis from 'ioredis';
const redis = new Redis({
port: 6379,
host: 172.22.0.2,
password: "password"
});
redis.on('pmessage', function(subscribed, channel, message) {
...
})但是我无法连接,因为我得到了这个错误:
ioredis未处理的错误事件:错误:连接ETIMEDOUT
我也在尝试改变ip和端口,比如:
port: 6379,
host: 127.0.0.1,或者改变码头上的端口-用1111组成,但还不能工作。我做错了什么?
发布于 2019-01-28 13:10:41
而不是使用容器ip地址,您可以使用name of the container,或者如果您正在使用docker-compose.yml,您可以使用name of the service而不是ip地址。因此,沿着这些路线的东西会起作用:
const redis = new Redis({
port: 6379,
host: laradock_redis_1
});https://stackoverflow.com/questions/54401020
复制相似问题