No output on python docker cron job

Published

I’ve been trying to set up a simple cron job in a docker container. When I build and run the job there are no errors but nothing is logged. If I go into the container I can see the crontab (i.e. crontab -l) and run the file (python test.py). Idk what I’m missing to see the scheduled job run. Idk if it’s running and my log location is wrong or if it’s not even running at all.

Dockerfile

FROM python:3.8.8
RUN apt-get update && apt-get -y install cron vim
WORKDIR /app
COPY crontab /etc/cron.d/crontab
COPY test.py /app/test.py
RUN chmod 0644 /etc/cron.d/crontab
RUN /usr/bin/crontab /etc/cron.d/crontab

# run crond as main process of container
CMD ["cron", "-f"]

crontab

* * * * * python /app/test.py > /proc/1/fd/1 2>/proc/1/fd/2
# new line

test.py

print('test')

Source: Docker Questions

Published
Categorised as cron, docker, python, python-3.8 Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq