I have a simple Dockerfile as follows
FROM ubuntu:latest
ADD crontab /etc/cron.d/test-cron
RUN chmod a+x /etc/cron.d/test-cron
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
and the content of crontab file is as simple as
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# empty line
When I run this on my local OS X machine (with docker-machine running), it works fine ("Hello world" is printed to log file every minute). However, when I try to run it on an Ubuntu machine, the cron job does not run (empty log file).
Here's the command I use to run the container
docker build -t crontest .
docker run --name cron crontest
I am not sure why this would be the case. I wonder if something is wrong with the Ubuntu box that I have (wrong time setting?). I have tried to restart that machine to no effect. I currently do have other docker containers running on the Ubuntu box and they're running fine.
Any suggestion on what I could do to debug/ fix this would be hugely appreciated.
EDIT:
After going inside the container (docker exec -it cron /bin/bash), I can verify that cron is running there:
root@a2ad451af8d9:/# ps -ef | grep cron
root 1 0 0 20:15 ? 00:00:00 /bin/sh -c cron && tail -f /var/log/cron.log
root 6 1 0 20:15 ? 00:00:00 cron
root 7 1 0 20:15 ? 00:00:00 tail -f /var/log/cron.log
root 25 11 0 20:21 ? 00:00:00 grep --color=auto cron