I have an Ubuntu 14.04 docker image that I want to schedule a python script within to execute every minute. My DockerFile contains CMD ["cron","-f"] in order to start the cron daemon. The crontab entry looks like this:
0,1 * * * * root python /opt/com.org.project/main.py >> /opt/com.org.project/var/log/cron.log
/opt/com.org.project/main.py is completely accessible and owned by root and has 744 privileges set; so can be executed.
Nothing is showing up in my /opt/com.org.project/var/log/cron.log file, nor /var/log/cron.log. Yet ps aux | grep cron shows cron -f running at PID 1.
What am I missing? Why is my cron job not running within the container?
Here are my DockerFile contents as requested:
FROM ubuntu
# Update the os and install the dependencies needed for the container
RUN apt-get update \
&& apt-get install -y \
nano \
python \
python-setuptools \
python-dev \
xvfb \
firefox
# Install PIP for python package management
RUN easy_install pip
CMD ["cron", "-f"]
Why use cron? Just write a shell script like this:
#!/bin/bash
while true; do
python /opt/com.org.project/main.py >> /opt/com.org.project/var/log/cron.log
sleep 60
done
Then just set it as entrypoint.
ENTRYPOINT ["/bin/bash", "/loop_main.sh" ]
Where did you use crontab -e? On the host running docker or in the container itself?
I can't see that you are adding an crontab entry in the dockerfile you provided. I recommend you to add an external crontab file like this:
ADD crontabfile /app/crontab
RUN crontab /app/crontab
CMD ["cron", "-f"]
The file crontabfile has to be located next to Dockerfile.
image_folder
|
|- Dockerfile
|- crontabfile
Example content of crontabfile:
# m h dom mon dow command
30 4 * * * /app/myscript.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With