Docker, Python and CRON

To use a CRON/scheduled Python application - don't need to invent a bicycle ;-)
Basically, the effort is close to zero.
CRON daemon is included in the official Python (base) Docker image.
And even in the "tiny" Alpine version!

Let's create a Python app (test.py):

from datetime import datetime
print ("Our test works at", datetime.now())

Then make a CRON-file like this:

* * * * *  python3 /app/test.py >>/tmp/out.log 2>/tmp/err.log

Now, build your own Docker image, based on Python one.
Your "Dockerfile" may look like this:

FROM python:3.9-alpine

# Add your application
COPY ./test.py /app/test.py

# Copy and enable your CRON task
COPY ./mycron /app/mycron
RUN crontab /app/mycron

# Create empty log (TAIL needs this)
RUN touch /tmp/out.log

# Start TAIL - as your always-on process (otherwise - container exits right after start)
CMD crond && tail -f /tmp/out.log

build it:

docker build . -t pcron

start it (daemon mode):

docker run -d pcron

check logs:

root@myserver:/opt/123# docker logs 1ae87155959a -f
Our test works at 2021-09-23 15:05:00.315992
Our test works at 2021-09-23 15:06:00.265267
Our test works at 2021-09-23 15:07:00.266187
Our test works at 2021-09-23 15:08:00.266758
Our test works at 2021-09-23 15:09:00.266371
Our test works at 2021-09-23 15:10:00.268429
Our test works at 2021-09-23 15:11:00.267884
Our test works at 2021-09-23 15:12:00.270521
Our test works at 2021-09-23 15:13:00.270120
Our test works at 2021-09-23 15:14:00.270855
Our test works at 2021-09-23 15:15:00.271388
Our test works at 2021-09-23 15:16:00.273039
Our test works at 2021-09-23 15:17:00.273109
Our test works at 2021-09-23 15:18:00.274327
Our test works at 2021-09-23 15:19:00.274991

That's it.