`django-cron==0.5.0`无法在`python:2.7`和`python:2.7-slim-buster`的docker镜像中运行预定的cron作业。

问题描述 投票:0回答:1

我把我的GitHub仓库链接分享给大家参考。https:/github.comdeepenpatel19test_django_cron。

在这里,我在Docker中设置了一个项目来测试cron调度器,但是,调度器没有按时运行。我必须手动运行。

Django的依赖性。

Django==1.8 
django-cron==0.5.0 
uwsgi==2.0.18 
django-common-helpers==0.9.2

Docker配置

FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
RUN apt-get update && apt-get purge nodejs && apt-get install -y --no-install-recommends gcc g++ default-libmysqlclient-dev libssl-dev libjpeg62-turbo-dev zlib1g-dev curl wget apt-transport-https gnupg2 nginx supervisor cron vim&& wget https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-x64.tar.xz && apt-get install -y xz-utils && tar -C /usr/local --strip-components 1 -xJf node-v6.4.0-linux-x64.tar.xz && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && apt-get update && apt-get install -y yarn && sed '/st_mysql_options options;/a unsigned int reconnect;' /usr/include/mysql/mysql.h -i.bkp && apt-get clean && pip install Django==1.8 django-cron==0.5.0 uwsgi==2.0.18 django-common-helpers==0.9.2&& rm -rf /var/lib/apt/lists/*  && rm -rf /root/.cache
ADD . /code/
RUN useradd --no-create-home nginx
RUN rm /etc/nginx/sites-enabled/default
RUN touch /var/log/cron.log
COPY nginx.conf /etc/nginx/
COPY django-site-nginx.conf /etc/nginx/conf.d/
COPY uwsgi.ini /etc/uwsgi/
COPY supervisord.conf /etc/supervisor/
WORKDIR /code
EXPOSE 8081
CMD ["/usr/bin/supervisord"]
django docker django-1.8 django-cron
1个回答
0
投票

你需要设置你的crontab并启动cron服务。为了测试每分钟的cron服务,我会在Docker中添加一个 django.cron 到项目的根目录下,并添加以下内容。

* * * * * /usr/local/bin/python /code/manage.py runcrons >> /code/cron.log 2>&1

然后,在你的 Dockerfile 添加。

COPY django.cron /etc/cron.d/
RUN crontab /etc/cron.d/django.cron

并将命令改为:

CMD /usr/sbin/cron && /usr/bin/supervisord
© www.soinside.com 2019 - 2024. All rights reserved.