简体   繁体   English

连接到 redis://redis:6379:6379 时出现错误 -2。 名称或服务未知

[英]Error -2 connecting to redis://redis:6379:6379. Name or service not known

I was hoping to get some insight to what I am missing, currently trying to run a docker-compose config with python (walrus for db wrapper) and redis image, but I keep receiving the same error:我希望对我所缺少的有所了解,目前正在尝试使用 python (数据库包装器的海象)和 redis 图像运行 docker-compose 配置,但我一直收到相同的错误:

redis.exceptions.ConnectionError: Error -2 connecting to redis://redis:6379. redis.exceptions.ConnectionError:连接到 redis://redis:6379 时出现错误 -2。 Name or service not known.名称或服务未知。

I tried different solutions on stack overflow to fix this but still nothing is working.我尝试了不同的堆栈溢出解决方案来解决这个问题,但仍然没有任何效果。

Here are the related docker-compose config:以下是相关的 docker-compose 配置:

version: '3.3'

services:

    redis:
      image: redis:latest
      container_name: redis
      ports:
        - "6379:6379"
      command: ["redis-server"]
      entrypoint: redis-server --appendonly yes

    consumers:
      build: ./consumers
      container_name: consumers
      environment:
        - REDIS_HOST=redis://redis
      command:  "./run.sh"
      depends_on:
        - redis
      restart: always
      tty: true


networks:
  default:
    driver: bridge

Dockerfile: Dockerfile:

FROM python:3.10

WORKDIR /consumers

# Copy Dependencies
COPY requirements.txt requirements.txt
COPY run.sh .

# Install Dependencies
RUN pip install -r requirements.txt

COPY . .
ENV REDIS_HOST=redis://redis
RUN chmod a+x run.sh

# Run executable consumer.py
CMD [ "./run.sh"]

And connection in python using walrus to redis:并在 python 中使用海象连接到 redis:

rdb = Database(host=os.getenv("REDIS_HOST", "localhost"), port=6379)

Locally without docker the setup works fine.在本地没有 docker 的设置工作正常。 Any direction in this case would be really appreciated.在这种情况下,任何方向都将不胜感激。

Thank you谢谢

The following configuration made it work, removed entrypoint, created a new custom network and exposed port.以下配置使其工作,删除入口点,创建新的自定义网络和公开端口。 REDIS_HOST was modified to redis ie container name. REDIS_HOST 修改为 redis 即容器名称。 All together made it work but while trying only one of these the problem persisted.所有这些都使它起作用,但是在仅尝试其中一种时,问题仍然存在。

version: '3.5'

services:

    redis:
      image: redis:latest
      container_name: redis
      ports:
        - "6379:6379"
      expose: 
        - 6379:6379
      command: ["redis-server"]
      networks:
        - connections

    
    consumers-g1:
      build: ./consumers
      container_name: consumers-g1
      environment:
        - REDIS_HOST=redis
      command: "./run.sh"
      expose: 
        - 6379:6379
      networks:
        - connections
      restart: always
      tty: true


networks:
  connections:
    name: connections
    driver: bridge

暂无
暂无

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

相关问题 redis.exceptions.ConnectionError: Error -2 连接到 localhost:6379。 名称或服务未知 - redis.exceptions.ConnectionError: Error -2 connecting to localhost:6379. Name or service not known Redis 错误 8 连接本地主机:6379。 提供了节点名或服务名,或未知 - Redis Error 8 connecting localhost:6379. nodename nor servname provided, or not known Docker 上的 Redis:连接到 0.0.0.0:6379 时出现错误 111。 拒绝连接 - Redis on Docker: Error 111 connecting to 0.0.0.0:6379. Connection refused redis.exceptions.ConnectionError:连接到 localhost:6379 时出现错误 97。 协议不支持的地址族 - redis.exceptions.ConnectionError: Error 97 connecting to localhost:6379. Address family not supported by protocol 连接到 localhost:6379 时出现错误 99。 无法分配请求的地址。 运行连接到redis的应用程序时 - Error 99 connecting to localhost:6379. Cannot assign requested address. when running app connected to redis 连接到 localhost:6379 时出现错误 111。 连接被拒绝。 姜戈赫鲁库 - Error 111 connecting to localhost:6379. Connection refused. Django Heroku 如何修复“连接到 localhost:6379 的错误 111。 当我启动 rq-worker 时连接被拒绝? - How to fix 'Error 111 connecting to localhost:6379. Connection refused' when I start rq-worker? Django中的Redis:redis.exceptions.ConnectionError:错误-2连接到127.0.0.1:20789:0。 名称或服务未知 - Redis in Django: redis.exceptions.ConnectionError: Error -2 connecting to 127.0.0.1:20789:0. Name or service not known channel_redis 在 docker-compose 网络模式桥接器中引发“名称或服务未知” - channels_redis raises "Name or service not known" in docker-compose network mode bridge 芹菜没有连接到Redis - Celery not connecting to Redis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM