0

I am trying to run celery in a separate docker container alongside a django/redis docker setup.

When I run docker-compose up -d --build, my logs via docker-compose logs --tail=0 --follow show the celery_1 container spamming the console repeatedly with

Usage: nc [OPTIONS] HOST PORT  - connect
nc [OPTIONS] -l -p PORT [HOST] [PORT]  - listen
    -e PROG Run PROG after connect (must be last)
    -l  Listen mode, for inbound connects
    -lk With -e, provides persistent server
    -p PORT Local port
    -s ADDR Local address
    -w SEC  Timeout for connects and final net reads
    -i SEC  Delay interval for lines sent
    -n  Don't do DNS resolution
    -u  UDP mode
    -v  Verbose
    -o FILE Hex dump traffic
    -z  Zero-I/O mode (scanning)

I am able to get celery working correctly by removing the celery service from docker-compose.yaml and manually running docker exec -it backend_1 celery -A proj -l info after docker-compose up -d --build. How do I replicate the functionality of this manual process within docker-compose.yaml?

My docker-compose.yaml looks like

version: '3.7'

services:
  backend:
    build: ./backend
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./backend/app/:/usr/src/app/
    ports:
      - 8000:8000
    env_file:
      - ./.env.dev
    depends_on:
      - db
      - redis
    links:
      - db:db
   celery:
     build: ./backend
     command: celery -A proj worker -l info
     volumes:
       - ./backend/app/:/usr/src/app/
     depends_on:
       - db
       - redis
  redis:
    image: redis:5.0.6-alpine
    command: redis-server
    expose:
      - "6379"
  db:
    image: postgres:12.0-alpine
    ports:
      - 5432:5432
    volumes:
      - /tmp/postgres_data:/var/lib/postgresql/data/

1 Answers1

0

I found out the problem was that my celery service could not resolve the SQL host. This was because my SQL host is defined in .env.dev which the celery service did not have access to. I added

env_file:
      - ./.env.dev

to the celery service and everything worked as expected.