0

I am trying to run my django application using a docker image with a scheduled cron job.

My Dockerfile is the following

FROM python:3.8-alpine3.10

WORKDIR /OuterDirectory

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PORT=8000

RUN apk update && apk add --update alpine-sdk

RUN apk add --no-cache tini openrc busybox-initscripts

COPY requirements.txt requirements.txt

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

RUN apk add --update npm

COPY . /OuterDirectory/

RUN npm install
RUN mkdir cron
RUN touch cron/cronlog.log
WORKDIR /OuterDirectory/Projectname

EXPOSE 8000
CMD python manage.py crontab add && python manage.py runserver 0.0.0.0:8000

In django settings I have properly added it to my INSTALLED_APPS.

CRONJOBS = [
    ('* * * * *', 'api.cron.testfunc', '>> ../cron/cronlog.log 2>&1'),
]

Everything in the docker image builds with no error.

I am 99% sure the issue is something to do with alpine linux and how to configure/get cron running on it but I am unable to find any resources. If anyone has any tips, please do help me I've been trying for a while lol

imbes
  • 71
  • 1
  • 6
  • 1
    Nothing to do with Alpine specifically: a Docker container only runs one process and not a full set of OS daemons, and your container is running only the Django server and not a cron daemon. In the linked question above I have a recipe for running a separate cron container based on the same image using Docker Compose. – David Maze Apr 18 '22 at 10:30
  • I appreciate it. Thank you. – imbes Apr 18 '22 at 15:23

0 Answers0