2

Assume this simple docker-compose file.

version: "3.9"
   
services:  
  redis:
    image: redis:alpine
    ports:
      - 6379:6379

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - redis

How can i add django-q worker to handle tasks from web container?

I could probably build same image with different command such as python manage.py qcluster but I dont think this solution si elegant. Could you suggest some approach how to do that?

ondrados
  • 272
  • 3
  • 9

1 Answers1

5

Probably the most easy thing that you can do is to add a new cluster for qcluster. Something like this:

version: "3.9"
   
services:  
  redis:
    image: redis:alpine
    ports:
      - 6379:6379

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - redis
  djangoq:
    build: .
    command: python manage.py qcluster
    volumes:
      - .:/code
    ports:
      - "8000:8001"
    depends_on:
      - redis
Ivan mile
  • 66
  • 1
  • 6
  • I am new at docker and I am confused... the same port (8000) for both clusters? – Dayanne Garcia Aug 12 '22 at 01:52
  • 2
    Well it depends on your qcluster setup... It's just an example :) And yes you might probably need to change TCP port of djangoq to be different then web TCP port. :) I edit the response. Thanks @DayanneGarcia – Ivan mile Aug 13 '22 at 10:52