Reputation: 360
I am totally new to the docker world.
I want to generate a new docker, that runs in the background on a server. Every day at 4:00 it has to invoke a bash script via cronjob.
Which container I have to choose? Do I have to generate a own from the scratch? Are there some that you can download? For mysql there was already one...
Thanks for helping!
Upvotes: 0
Views: 48
Reputation: 3691
You've an example on Ekito's web:
As far as I've been requested to put here content of this link, let me copy it under these lines:
The following DockerFile describes all the steps to build your image
FROM ubuntu:latest
MAINTAINER [email protected]
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
Then you can build the image with
sudo docker build --rm -t ekito/cron-example .
After that, you can create task in crontab:
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.
Upvotes: 1
Reputation: 3045
containers (docker) doesn't support cronjob functionality by default. You have to install packages inside container to achieve it.
To run conatiner in background, you can set it as daemon (using -d if using docker run).
Yes, people have developed images for this functionality. I just searched on internet and could see them on github. Choose what suits best for your requirement.
Upvotes: 0