Celery-container error (exited with code 1) after installing and adding django-crontab to INSTALLED_APPS in settings.py

I work on a django project, which needs celery for running some tasks in the background. I also need to run some cron-jobs, so I installed django-crontab into the container, added to the INSTALLED_APPS in settings.py, "python manage.py crontab show" OUTPUT:

root@865809c7149e:/apps# python manage.py crontab show
Currently active jobs in crontab: ab590d03e928be09c5fc1a0048404548 -> ('*/3 * * * *', 'AppName.cron.cron_job_method', '>> /apps/crontab.log')

SADLY no crontab.log file appears... I don't understand why...

AND:

celery container exits on "docker compose up" with:

... celery-1 | ModuleNotFoundError: No module named 'django_crontab' celery-1 exited with code 1 web-1 | Watching for file changes with StatReloader

Here my docker-compose.yml

services:
db:
    image: postgres:17
    env_file: .env
    volumes:
        - ./local-db:/var/lib/postgresql/data

redis:
    image: redis:7

web:
    build: .
    command: python manage.py runserver 0:8030
    ports:
        - 8030:8030
    volumes:
        - ./projectDIR:/apps
    env_file: .env
    links:
        - db
    depends_on:
        - db
        - redis

celery:
    build: .
    command: celery -A projectDIR worker -l INFO
    env_file: .env
    volumes:
        - ./projectDIR:/apps
    environment:
        redis_url: redis://redis:6379/0
    links:
        - db
        - redis
        - web
    depends_on:
        - web
        - redis

ANY HELP IS VERY APPRECIATED!

So after hours of desperation I finally came to a solution (in case somebody has similar issues...):

  1. I commented out all lines of code referring to crontab (#) in django settings.py module to avoid the error...
  2. then i ran docker (to be able to exec bash):

docker compose up 3. so I could bring up the terminal of celery container $ docker compose exec celery bash 4. where I simply executed a pip install: $ pip install django-crontab 5. Finally - after a cheap Ctrl+C - I restarted the container (step.2)

And Voila, NO ERRORS!

Вернуться на верх