admin管理员组文章数量:1188441
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!
Dockerfile:
FROM python:3.12
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install -y cron
RUN mkdir /apps
WORKDIR /apps
COPY projectDIR .
requirements.txt
Django==5.1.3
djangorestframework==3.15.2
django-debug-toolbar==4.4.6
django-crontab==0.7.1
psycopg==3.2.3
pandas==2.2.3
pillow==11.0.0
openpyxl==3.1.5
celery==5.4.0
celery-progress==0.4
django-celery-results==2.5.1
redis==5.2.0
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!
Dockerfile:
FROM python:3.12
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install -y cron
RUN mkdir /apps
WORKDIR /apps
COPY projectDIR .
requirements.txt
Django==5.1.3
djangorestframework==3.15.2
django-debug-toolbar==4.4.6
django-crontab==0.7.1
psycopg==3.2.3
pandas==2.2.3
pillow==11.0.0
openpyxl==3.1.5
celery==5.4.0
celery-progress==0.4
django-celery-results==2.5.1
redis==5.2.0
Share
Improve this question
edited Jan 25 at 11:49
baloersch
asked Jan 25 at 8:02
baloerschbaloersch
111 silver badge4 bronze badges
4
|
1 Answer
Reset to default 0So after hours of desperation I finally came to a solution (in case somebody has similar issues...):
- I commented out all lines of code referring to crontab (#) in django settings.py module to avoid the error...
- 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!
本文标签:
版权声明:本文标题:docker - celery-container error (exited with code 1) after installing and adding django-crontab to INSTALLED_APPS in settings.py 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738369489a2082222.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
django-crontab
? You should delete the obsoletelinks:
blocks in the Compose file, and thevolumes:
that overwrite the entire image/apps
directory can lead to unexpected results. – David Maze Commented Jan 25 at 11:00django-crontab
is in fact in therequirements.txt
file. – David Maze Commented Jan 25 at 11:43