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:


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

import time
print ("Hello World!")


FROM ubuntu:20.04

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

COPY crontab /opt
COPY /bin/
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/ > /var/log/somelogfile.txt 2>&1 and file with ‘hello world’ is created.

But not by Cron job.

Source: Docker Questions