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.
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"]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments