I am attempting to start cron automatically in an Ubuntu 20.10 (Groovy Gorilla) Docker container, thus far without success.
From previous searches (example), I've found a method to start cron using Dockerfile as follows:
# Install and enable cron
RUN apt-get install systemd -y
RUN apt-get install cron -y
RUN systemctl enable cron
# Copy cron file to the cron.d directory
COPY cronfile /etc/cron.d/cronfile
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cronfile
# Apply cron job
RUN crontab /etc/cron.d/cronfile
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
However, I can't make this work with my server setup. I have another, later, CMD in my Dockerfile (similar to this):
CMD ["/usr/sbin/run-lamp.sh"]
and of course only the second CMD will be run. I have tried combining multiple commands:
CMD cron && tail -f /var/log/cron.log && /usr/sbin/run-lamp.sh
but this does not run run-lamp.sh. I also tried putting the commands inside run-lamp.sh, but nothing has resulted in cron starting. Having said that, it is very easy to start cron manually, by opening up a shell in the container and entering the following:
# cron
# crontab /etc/cron.d/cronfile
I am open to suggestions.
All the files I'm working with are available here:
https://github.com/Downes/gRSShopper
In particular: Dockerfile:
https://github.com/Downes/gRSShopper/blob/master/Dockerfile
run-lamp.sh:
https://github.com/Downes/gRSShopper/blob/master/run-lamp.sh
cronfile:
https://github.com/Downes/gRSShopper/blob/master/cronfile
Thanks in advance.