Issue
I'm trying to run cron job through Docker entrypoint file.
Dockerfile:
FROM python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update -y && apt-get install -y build-essential postgresql python-scipy python-numpy python-pandas cron libgdal-dev && apt-get clean && rm -rf /var/lib/apt/lists/*
COPY ./django-entrypoint.sh .
RUN mkdir /industrialareas
WORKDIR /industrialareas
COPY ./project .
COPY ./requirements.txt .
RUN chmod 755 /django-entrypoint.sh
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["/django-entrypoint.sh"]
django-entrypoint.sh:
#!/bin/bash
# Django
python /industrialareas/manage.py collectstatic --noinput
python /industrialareas/manage.py migrate
python /industrialareas/manage.py runserver 0.0.0.0:8000
# Cron
service cron restart
service cron status
python /industrialareas/manage.py crontab add
python /industrialareas/manage.py crontab show
exec "$@"
But only works Django commands because i check it
service cron status
and is stopped and python manage.py crontab show
and method not added.
If i run script manually works well ./django-entrypoint.sh
. The cron job is executed and i can see the output on log file.
Anybody could help me please ? Thanks in advance.
Solution
Changing commands order solve the problem, the cron service start and job works well.
django-entrypoint.sh:
#!/bin/bash
# Cron
service cron restart
python /industrialareas/manage.py crontab add
# Django
python /industrialareas/manage.py collectstatic --noinput
python /industrialareas/manage.py migrate
python /industrialareas/manage.py runserver 0.0.0.0:8000
exec "$@"
Answered By - Alberto Sanmartin Martinez Answer Checked By - David Marino (WPSolving Volunteer)