0

I have this Dockerfile (where I am using miniconda just because I would like to schedule some python scripts, but it's a debian:jessie docker image):

FROM continuumio/miniconda:4.2.12

RUN mkdir -p /workspace
WORKDIR /workspace
ADD volume .

RUN apt-get update
RUN apt-get install -y cron

ENTRYPOINT ["/bin/sh", "/workspace/conf/entrypoint.sh"]

The script entrypoint.sh that keeps the container alive is this one:

#!/usr/bin/env bash

echo ">>> Configuring cron"
service cron start
touch /var/log/cron.log
mv /workspace/conf/root /var/spool/cron/crontabs/root
chmod +x /var/spool/cron/crontabs/root
crontab /var/spool/cron/crontabs/root
echo ">>> Done!"

tail -f /var/log/cron.log

From the docker documentation about supervisor (https://docs.docker.com/engine/admin/using_supervisord/) it looks like that could be an option as well as the bash script option (as in my example), that's why I decided to go for the bash script and to ignore supervisor.

And the content of the cron details /workspace/conf/root is this:

* * * * * root echo "Hello world: $(date +%H:%M:%S)" >> /var/log/cron.log 2>&1

(with at the bottom as an empty line \n)

I can not find a way to see that Hello world: $(date +%H:%M:%S) each minute appended to /var/log/cron.log, but to me all the cron/crontab settings are correct.

When I check the logs of the container I can see:

>>> Configuring cron
[ ok ] Starting periodic command scheduler: cron.
>>> Done!

Also, when logging into the running container I can see the cron daemon running:

root@2330ced4daa9:/workspace# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.0   4336  1580 ?        Ss+  13:06   0:00 /bin/sh /workspace/conf/entrypoint.sh
root         14  0.0  0.0  27592  2096 ?        Ss   13:06   0:00 /usr/sbin/cron
root         36  0.0  0.0   5956   740 ?        S+   13:06   0:00 tail -f /var/log/cron.log
root        108  0.5  0.1  21948  3692 ?        Ss   13:14   0:00 bash
root        114  0.0  0.1  19188  2416 ?        R+   13:14   0:00 ps aux

What am I doing wrong?

TPPZ
  • 4,447
  • 10
  • 61
  • 106
  • Docker is 'a process on steroids'. As in: a single process. Not a virtual machine. You cannot assume `init` or `systemd` run for you to just hand off the `cron` daemon task. – Dirk Eddelbuettel Apr 03 '17 at 14:25
  • Possible duplicate of [Docker: Cronjob is not working](http://stackoverflow.com/questions/24943982/docker-cronjob-is-not-working) – Mark O'Connor Apr 03 '17 at 14:27
  • From the docker documentation about `supervisor` it looks like that could be an option as well as the `bash` script option (as in my example), that's why I decided to go for the bash script and to ignore `supervisor`. I am not sure I get why that bash script is wrong. I also tried replacing in that bash script the line `service cron start` with the line `cron` with no success. – TPPZ Apr 03 '17 at 14:49

1 Answers1

0

Are you sure the Cronjob has execution rights?

chmod 0644 /var/spool/cron/crontabs/root
Frenus
  • 780
  • 5
  • 13