Hopefully this is the correct place as I’m experiencing some issues when trying to install cron in Quay.
Here is my existing Dockerfile which is working like a charm and jupyterlab runs successfully
FROM quay.io/jupyterhub/k8s-singleuser-sample:3.2.1
USER root
# requirements for the pip packages
RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
gcc libpq-dev python3-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
USER ${NB_USER}
ENTRYPOINT ["tini", "--"]
CMD ["jupyter", "lab"]
but when I try to add cron , for example
FROM quay.io/jupyterhub/k8s-singleuser-sample:3.2.1
USER root
# requirements for the pip packages
RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
gcc libpq-dev python3-dev cron\
&& rm -rf /var/lib/apt/lists/*
# Copy crontab file to the cron.d directory
COPY crontab-example /etc/cron.d/crontab
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab
# Apply cron job
RUN crontab /etc/cron.d/crontab
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run the command on container startup
RUN service cron start
#RUN sudo journalctl -u cron.service
RUN service cron status
COPY requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
USER ${NB_USER}
ENTRYPOINT ["tini", "--"]
CMD ["jupyter", "lab"]
building fails with
=> ERROR [7/9] RUN service cron status 0.1s
------
> [7/9] RUN service cron status:
0.106 cron is not running ... failed!
ERROR: failed to solve: process "/bin/sh -c service cron status" did not complete successfully: exit code: 1
UPDATE: When trying to start service from docker and not start it via dockerfile, i get
Starting periodic command scheduler: croncron: can't open or create /var/run/crond.pid: Permission denied
failed!
Any ideas or is there a better way to do it?
Thanks in advance for the support and help
paparoup
Most container images don’t support the usual operating system services. They’re intended to be minimal systems that just provide the required applications.
It’s possible to get cron to run in a container, see these previous topics:
Yeap , I totally get your point with minimal images but there are cases that at least cron is needed but I will also try to find another way.
In the meantime , If you check the Dockerfile example, have followed the exact link that you shared with the change being only replacing how cron starts
CMD cron
with
RUN service cron start
in the root part in order to check if the service would start but doesn’t seem to and cron service fails to start.
Having two CMD parts, one for root and one for user wouldn’t be a problem right ? Dockerfile wise i mean.
but even though it works locally , when applied in k8s the cron service isn’t started
Documented the above for anyone that may end up in this thread due to troubleshooting
That said,I don’t think that my initial thinking makes any sense as I was trying to create a VM-like crontabs in images that are minimal for a reason and should stay like this. So I have installed Jupyter Scheduler — jupyter_scheduler documentation and now users can do whatever they want via python notebooks/scripts.
Thanks a lot for taking the time, I would say that my initial plan is rejected