Reputation: 35
I have three files which is
crontab : lists of cron job to be execute
entrypoint.sh
#!/usr/bin/env bash
service cron start python
and docker file basically to install the pip and to run crontab on certain folder.
My question is : Why in my docker container, the cron just start once and Exited. have no ways to find the logs of it as it shows : Starting periodic command scheduler: cron.
i wish to know whats the proper way of setting up and how to keep it running.
Thanks
Upvotes: 1
Views: 448
Reputation: 408
There are multiple ways on how you can run a cronjob inside a docker container. Here is an example for a cron-setup on debian using cronjob files.
* * * * * root echo "Test my-cron" > /proc/1/fd/1 2>/proc/1/fd/2
my-cron - This file contains the interval, user and the command that should be scheduled. In this example we want to print the text Test my-cron every minute.
#!/usr/bin/env bash
cron # start cron service
tail -f /dev/null # keep container running
entrypoint.sh - This is the entrypoint which gets executed when the container gets started.
FROM debian:latest
RUN apt-get update \
&& apt-get install -y cron
# Cron file
ADD ./my-cron /etc/cron.d/my-cron
RUN chmod 0644 /etc/cron.d/my-cron
# Entrypoint
ADD ./entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod +x /usr/bin/entrypoint.sh
CMD [ "entrypoint.sh" ]
docker build . --tag my-cron
docker run -d my-cron:latest
docker logs <YOUR_CONTAINER_ID> --follow
Upvotes: 1