Alpine: "service `crond' does not exist"

Viewed 5905

I'm trying to run an Node 12.13.0 Alpine Docker container that runs a script every 15 minutes. According to Alpine's wiki cron section, I should be able to just add a RUN task in the Dockerfile to run crond as a service via:

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

This however returns an error:

rc-service: service `crond' does not exist

Running a separate Docker container just to run the cron task against this Docker container is NOT an option. This container is already extremely lightweight, and doesn't do much.

Here is my Dockerfile:

FROM node:12.13.0-alpine

RUN apk add --no-cache tini openrc

WORKDIR /opt/app

COPY script.sh /etc/periodic/15min/

RUN chmod a+x /etc/periodic/15min/script.sh

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

COPY . .

RUN chmod a+x startup.sh

ENTRYPOINT ["/sbin/tini", "--"]

CMD ["./startup.sh"]

Any help here would be appreciated.

2 Answers

The issue was that some Alpine Docker containers come without the busybox-initscripts package installed. After installing this, crond is running as a service. One other hiccup I ran into is that run-parts, the command the executes the files in the /etc/periodic folders expects there to be no extension, so I stripped that, and everything is working now.

The working Dockerfile looks like this:

FROM node:12.13.0-alpine

RUN apk upgrade --available

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

WORKDIR /opt/app

COPY runScraper /etc/periodic/15min/

RUN chmod a+x /etc/periodic/15min/runScraper

COPY . .

RUN chmod a+x startup

ENTRYPOINT ["/sbin/tini", "--"]

CMD ["./startup"]

Alpine might've changed how things work since the last solution was published, now it just reports back:

 # rc-service crond start
 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel
 * ERROR: syslog failed to start
 * ERROR: cannot start crond as syslog would not start

Failing silently during the installation of "busybox-initscripts" which activates it automatically.

The important bit being:

touch /run/openrc/softlevel

which makes it work, note that you still need the rest of the previous solution installed, that is "openrc" and "busybox-initscripts".

Related