0

I am trying to run my two python files with cron in docker. I have two files a.py and b.py, which are to be run with cron and specific time period between them.

How to approach this through docker?

1 Answers1

0

Here is what I am using. You can refer

 FROM ubuntu:latest

# Install cron
RUN apt-get update
RUN apt-get install cron
RUN apt-get install -y python3
RUN apt-get install -y python3-pip

# Add crontab file in the cron directory
ADD crontab /etc/cron.d/simple-cron

# Add shell script and grant execution rights
ADD dir/ /
ADD requirements.txt /
ADD script.sh /script.sh
WORKDIR /
RUN pip3 install -r requirements.txt
RUN chmod +x /script.sh

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/simple-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh && cron && tail -f /var/log/cron.log
Patel
  • 200
  • 2
  • 9
  • Hi ! Can you please share your simple-cron file. Also I am not able to see anything in my cron.log file. Can you please help me with that? – Shivangi Bhardwaj Jul 02 '19 at 10:41