So I want to run cronjob.py
inside a container every week. I tried some of the codes from other posts but I can't manage to get cron to work.
This is my Dockerfile:
FROM python:3.7
RUN apt-get update && apt-get install cron vim systemctl -y
WORKDIR /app
RUN pip3 install flask
COPY harborscan /etc/cron.d/harborscan
COPY cronjob.py cronjob.py
RUN systemctl start cron
RUN chmod 0644 /etc/cron.d/harborscan
RUN crontab /etc/cron.d/harborscan
RUN touch /app/cron.log
CMD ["cron", "-f"]
And the crontab file:
* * * * * /bin/touch /app/test >/app/cron.log 2>&1
So just for testing purposes I left the schedule to each minute and a simple touch
command.
The cron services is running:
root@6b6c056d0039:/app# systemctl status cron
cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service, enabled)
Active: inactive (dead)
crontab -l :
root@6b6c056d0039:/app# crontab -l
* * * * * /bin/touch /app/test >/app/cron.log 2>&1
The test
file is not created, I also tried to just run /usr/bin/python3 app/cronjob.py
but the API calls that it is supposed to make aren't being executed.