Luc Shelton

CRON Jobs with Alpine Linux and Docker

CRON Jobs with Alpine Linux and Docker

CRON Jobs with Alpine Linux and Docker

CRON Jobs with Alpine Linux and Docker

Updated 2 years ago
2 Minute(s) to read
Posted 2 years ago Updated 2 years ago 2 Minute(s) to read 15 comments

I recently added some CRON job scripts as part of my Docker container image so that SilverStripe tasks could be executed on a regular basis. Unfortunately when I first configured the CRON daemon to run the scripts, I noticed that they were never being executed at the configured interval (found in crontab -l). The reason for this is because the CRON daemon is never launched when the Docker container is booted up for the first time. In part this is because there isn't an "init system" that is included as part of the Docker image for Alpine Linux, and additionally it does not come with the "init scripts" (configuration files for starting processes) for the CRON daemon (crond).

If you're looking to run automated CRON jobs from your Alpine Docker container, you are going to want to do the following.

Install System Packages

Make sure to install the following packages.

apk add busybox-initscripts openrc --no-cache

Or include it as part of your Dockerfile.

RUN apk add busybox-initscripts openrc --no-cache

This should ensure that the init system starts on boot, alone with the crond process.

Tweak CRON Configuration

Ensure that your CRON configuration looks like this if you are intending on using the run-parts tool. This is modifiable from the /etc/crontabs/root file, if you are running as the root user (I don't recommend that you do).

*/1 * * * * run-parts /etc/periodic/1min

Additionally, ensure that any scripts that are stored under directories such as /etc/periodic/15min and /etc/periodic/1min DO NOT specify the .sh file extension, as the script will not be executed if they are.

Finally, ensure that the script itself has the relevant permissions.

chmod -R a+x /etc/periodic/1min

If you want to test the scripts that are placed under the path /etc/periodic/1min, run the following command.

run-parts --test /etc/periodic/1min

Start the CRON Daemon

Run the following command to ensure that the CRON daemon starts as part of the daemon.

rc-service crond start && rc-update add crond

And now it should be running as expected.



You explained that perfectly.
<a href="">parts of a research proposal</a> research paper services <a href="">research paper help</a> thesis proposal
<a href=>customer service essay</a> writing an argumentative essay <a href=>best essay writing service reddit</a> pro essay writing service
dos and don ts of college essays

Wonderful postings. Cheers.
<a href="">do my math homework for me</a> cpm homework <a href="">do my math homework</a> pay to do my homework

Thanks! A good amount of facts!
<a href="">dissertation writing</a> custom dissertation writing services <a href="">phd dissertation</a> phd thesis

You actually stated that really well.
<a href="">writing help</a> dissertation help <a href="">dissertation writing service</a> phd thesis

Many thanks, A lot of posts!
<a href="">custom essay writing</a> write my essay service <a href="">best essay writing service australia</a> essay writing help

Nicely put. Regards!
<a href="">can you do my homework</a> do my finance homework <a href="">pay to do my homework</a> pay to do my homework
<a href=>essays help</a> cheap essay help <a href=>college application essay help</a> medical school personal statement
how to write short essay

Regards. An abundance of knowledge!
<a href="">dissertation definition</a> dissertations online <a href="">dissertation def</a> define dissertation

Kudos. I appreciate it.
<a href="">graduate paper writing service</a> paper writing service reviews <a href="">pay someone to write your paper</a> order custom paper
<a href=>pay to write paper</a> buy essay papers <a href=>buy an essay</a> pay for papers
essays website

You've made your point.
<a href="">dissertation writing services</a> dissertation abstract <a href="">dissertation abstract</a> phd thesis

Whoa all kinds of awesome info!
<a href="">write my research paper for me</a> professional essay writers <a href="">writing a persuasive essay</a> what should i write my college essay about
<a href=>write a essay</a> writing a personal essay <a href=>persuasive essay writer</a> essay writer website
best resume writing services nyc