Crond #
Sometimes what we are familiar with most, works best.
When containerizing an application there are constantly new things to learn and time is often of the essence. Using a familiar technology such as crond
can save time (initially) which can be of advantage.
We don't recommend the following method but we like and value pragmatic problem-solving. Please read up on [delayed restarts](/common-tasks/cronjobs/delayed-restarts/) and [swarm-cronjob](/common-tasks/cronjobs/swarm-cronjob/) as well and consider a more Docker-friendly approach to running periodic tasks.
Example #
Building upon the example setup we mentioned, we add the following to the project:
A file with a your crontab, my-crontab
:
*/15 * * * * /usr/local/bin/mc cp -r /backup minio-alias/bucket > /proc/1/fd/1 2>/proc/1/fd/2
This instructs crond
to execute /usr/local/mc
every 15 minutes.
… and a Dockerfile
:
|
|
In detail:
- The
cron
package is installed, crontab file is copied (into the image) and setup. - The
mc
utility is copied into the image. - We start
cron(d)
in the foreground (to be able to see potential logs from runs).
Build and publish the docker image:
$ docker build -t registry.example.org/project/backup:latest .
...
$ docker push registry.example.org/project/backup
...
Add the following to your stack’s docker-compose.yml
and deploy the stack:
|
|
Further updates to the schedule require an image rebuild and another deployment.