Home > other >  Error -3 connecting to redis:6379. Temporary failure in name resolution
Error -3 connecting to redis:6379. Temporary failure in name resolution

Time:11-10

I try to implement Celery to my FastAPI project, using Redis as broker and backend result. I build the app successfully docker compose. However when I send request it raises Error -3 connecting to redis:6379. Temporary failure in name resolution. Here is my docker-compose.yaml file content. What do I miss?

By the way what is the /0 in the end of the Redis url?

version: '3.5'

services:
  soar-core:
    container_name: soar-core
    build: .
    stdin_open: true
    tty: true
    restart: on-failure
    ports:
      - 127.0.0.1:8000:8000
    depends_on:
      - mongo
      - redis
    volumes:
      - .:/soar_core
    networks:
      - soar-network
  mongo:
    container_name: mongo
    image: mongo
    restart: always
    ports:
      - 127.0.0.1:27018:27017
    volumes:
      - ./data:/data/db
    networks:
      - soar-network
  redis:
    image: redis:7.0.5
  worker:
    build: .
    command: pipenv run celery --app=soar_core.celery.app worker --loglevel=info
    volumes:
      - .:/soar_core
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - soar-core
      - redis
  dashboard:
    build: .
    command: pipenv run --app=soar_core.celery.app flower --port=5555 --broker=redis://redis:6379/0
    ports:
      - 5556:5555
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - soar-core
      - redis
      - worker
networks:
  soar-network:
    driver: bridge

Here is how I configure celery.

from celery import Celery
app = Celery(
    name="Celery-App",
    broker="redis://redis:6379/0",
    backend="redis://redis:6379/0",
)

CodePudding user response:

Two of your services have a custom networks: [soar-network] block, but the remainder don't. Compose automatically puts these on a default network that it creates.

There's nothing wrong with using the default network, and I'd recommend deleting all of the networks: blocks in the file so that every container is on that default network.

(The redis://.../0 specifies the database number. A Redis server can have multiple key spaces, but they are identified numerically and not by name.)

  • Related