Context
I'm trying to schedule some ingestion jobs in an Alpine container. It took me a while to understand why my cron jobs did not start: crond doesn't seems to be running
rc-service -l | grep crond
According to Alpine's documentation, crond must first be started with openrc
(i.e. some kind of systemctl
). Here is the Dockerfile
FROM python:3.7-alpine
# set work directory
WORKDIR /usr/src/collector
RUN apk update \
&& apk add curl openrc
# ======>>>> HERE !!!!!
RUN rc-service crond start && rc-update add crond
# install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /usr/src/collector/Pipfile
RUN pipenv install --skip-lock --system --dev
# copy entrypoint.sh
COPY ./entrypoint.sh /usr/src/collector/entrypoint.sh
# copy project
COPY . /usr/src/collector/
# run entrypoint.sh
ENTRYPOINT ["/usr/src/collector/entrypoint.sh"]
entrypoint.sh
merely appends the jobs at the end of /etc/crontabs/root
Problem
I'm getting the following error:
* rc-service: service `crond' does not exist
ERROR: Service 'collector' failed to build: The command '/bin/sh -c rc-service crond start && rc-update add crond' returned a non-zero code: 1
Things are starting to feel a bit circular. How can rc-service not recognizing a service while, in the same time:
sh
seems to know the namecrond
,there was a
/etc/crontabs/root
What am I missing?
docker-compose
environment. – RattletrapRUN rc-service crond start && rc-update add crond
withRUN crond
– SukiyakiRUN crond
orCMD crond -f
at the end of the docker file but it does not seem to change a thing: no cron jobs and crond is still missing from the list of rc-services. I think that this is th issue – Freyahcron
run in the same container as your application, I believe. That just causes drama, every time ;-). My approach, and the one that I have seen used by many others, is to run it in a separate container. – Rattletrap