Cron Job in Docker not working – python app

  cron, docker, dockerfile, jobs, python

Content within Cron Job seems that’s not being executed or there is a problem with saving logs. Let me introduce you to my files:

crontatab

* * * * * python /bin/wrapper.py > /var/log/somelogfile.txt 2>&1

wrapper.py

import time
print ("Hello World!")
time.sleep(2)

Dockerfile

FROM ubuntu:20.04

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

COPY crontab /opt
COPY wrapper.py /bin/wrapper.py
RUN crontab /opt/crontab

CMD busybox syslogd -C; cron -L 2 -f

In the running docker I can see that Cron Job is scheduled in each minute (busybox logread):
enter image description here

But logs (so actually "hello world") are not saved into /var/log/somelogfile.txt
I don’t know if content is executed within Crontab job or the there is problem with log. I would like to have it saved into log file.

FYI, I can run following command directly from the running docker (-it mode in Docker; /bin/bash):
python /bin/wrapper.py > /var/log/somelogfile.txt 2>&1 and file with ‘hello world’ is created.

But not by Cron job.

Source: Docker Questions

LEAVE A COMMENT