djangodocker-composedjango-q

How to deploy django-q worker with docker?


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?


Solution

  • 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