简体   繁体   English

我无法从 Docker 中的节点映像连接到 Redis 映像

[英]I cannot connect to Redis image from a Node image within Docker

First all was working great with default configuration until I hit one memory limit, then I needed to add a Redis configuration file (latest, 7.0).首先,在我达到一个内存限制之前,默认配置一切正常,然后我需要添加一个Redis 配置文件(最新,7.0)。 In this file bind is set to 127.0.0.1 with default port, so I tried that.在这个文件中,bind 设置为127.0.0.1 ,默认端口,所以我试过了。 I also changed that to bind 0.0.0.0 but I got the same error.我也将其更改为bind 0.0.0.0但我得到了同样的错误。

Now in for my environment variables I'm putting: ~redis//redis:6379~ or redis:6379 so here is my configuration (docker-compose.yml):现在输入我的环境变量: ~redis//redis:6379~ 或redis:6379所以这是我的配置(docker-compose.yml):

version: '3.7'
services:
  classified-ads:
    container_name: classified-ads
    depends_on:
      - redis-service
    ports:
      - 3000:3000
    build:
      context: ./
    # restart: unless-stopped
    environment:
      - REDIS_URI=redis:6379
      - INSIDE_DOCKER=wahoo
  # our custom image 
  redis:
      container_name: redis-service
      build:
        context: ./docker/redis/
      privileged: true
      command: sh -c "./init.sh"
      ports:
        - '6379:6379'
      volumes: 
        - ./host-db/redis-data:/data/redis:rw

The error I'm getting is bloated and is from my client which is ioredis but it is clearly a connection error.我得到的错误是臃肿的,来自我的客户端,它是ioredis ,但它显然是一个连接错误。 (ioredis wrapped with Fastify/redis, so it is a failed promise that is very verbose but not clearly indicative, but it's 100% a connection error). (ioredis 用 Fastify/redis 包裹,所以这是一个失败的承诺,非常冗长但没有明确指示,但它是 100% 的连接错误)。

I checked Redis logs piped to Docker and it is running fine.我检查了通过管道传输到 Docker 的 Redis 日志,它运行良好。

Edit: ping redis//redis:6379 does not work from my app image while ping redis:6379 works so I changed that.编辑: ping redis//redis:6379在我的应用程序映像中不起作用,而ping redis:6379起作用,所以我改变了它。

I found the sollution.我找到了解决方案。 While the default redis:alpine image use configuration with protection_mode yes I was using a new configuration with protection_mode no .虽然默认 redis:alpine 图像使用配置protection_mode yes我正在使用一个新配置protection_mode no I also removed the bind 'address' all together.我还一起删除了bind 'address'

And reconnected normally from other services with redis:port as usual.并像往常一样使用redis:port从其他服务重新连接。 all thanks to https://stackoverflow.com/a/57541475/1951298感谢https://stackoverflow.com/a/57541475/1951298

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM