Reputation: 41
I'm using the current time to develop myself a little bit and I decided to invest some time in Docker Containers.
I created myself some small learning excercises where I am working on now.
I have an Issue with my Cronjobs. It should be a cronjob which is running every minute. Runtime of the completed scripts will be something around 40-50 seconds. Therefore I decided not to start a container every minute, I want to keep the container running and run the cronjobs inside the container.
My Issue: Cronjob is not starting.
#Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get -yq install cron
COPY scripts/cmd.txt /home/cmd.sh
RUN chmod 744 /home/cmd.sh
COPY scripts/cron.txt /etc/cron.d/test-cron
RUN chmod 644 /etc/cron.d/test-cron
RUN crontab /etc/crontab.d/test-cron
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
# scripts/cmd.txt
echo "test aus CMD" >> /var/log/cron.log
# scripts/cron.txt
* * * * * root /home/cmd.sh >> /var/log/cron.log 2>&1
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
From my understanding the /var/log/cron.log should get some content over time but nothing happens. I'm pretty sure that's me who caused this error but I'm not finding it.
Anybody an Idea what I did wrong?
Thanks and kind regards Holger
Upvotes: 0
Views: 62
Reputation: 46
There are a few typos in your files.
#Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get -yq install cron
COPY scripts/cmd.txt /home/cmd.sh
RUN chmod 744 /home/cmd.sh
COPY scripts/cron.txt /etc/cron.d/test-cron
RUN chmod 644 /etc/cron.d/test-cron
RUN crontab /etc/crontab.d/test-cron # Here it is, just replace `crontab.d` by `cron.d`
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
# scripts/cron.txt
* * * * * root /home/cmd.sh >> /var/log/cron.log 2>&1 # Remove the `root` command from this line...
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1 # ...and also from that one
Upvotes: 1