I have a python script that populates Postgres database in AWS.
I am able to run it manually and it is loading data into database without any issues. I want to run it once for every 5 minutes inside a docker container.
So I included it in docker image to run. But I'm not sure why it's not running. I can't see anything appended to /var/log/cron.log
file. Can someone help me figure out why it's not running?
I am able to copy the script to image during docker build and able to run it manually. The DB is being populated and I'm getting the expected output.
The script is in current directory which will be copied to /code/
folder
Here is my code:
Dockerfile:
FROM python:3
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y cron
RUN apt-get install -y postgresql-client
RUN touch /var/log/cron.log
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD . /code/
COPY crontab /etc/cron.d/cjob
RUN chmod 0644 /etc/cron.d/cjob
CMD cron && tail -f /var/log/cron.log
crontab:
*/5 * * * * python3 /code/populatePDBbackground.py >> /var/log/cron.log
# Empty line
&& tail -f /var/log/cron.log
to yourCMD cron
not work? – Frendelcat /var/log/cron.log
. Correct me if I'm wrong. Is it mandatory to addtail
? – Oxcron -f
has the same effect. – Frendeltail -f /var/log/cron.log
– Oxchmod 0644 /etc/cron.d/cjob
helped me out – Apraxia