INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

Cron inside your Docker image with python app

№ 9577 В разделе Sysadmin от November 25th, 2018,
В подшивках: ,

At first, create your cron file with usual crontab lines and name it mycrontab_lines

*/5 * * * * /app/

Now create your

# load env variables
source /etc/profile
. ~/.profile

python3 /app/

Ok, you ready now to create Dockerfile like this:

FROM python:3

# install cron service
RUN    apt-get ${APT_FLAGS_COMMON} update && \
    apt-get ${APT_FLAGS_PERSISTENT} -y install cron && \
    apt-get ${APT_FLAGS_COMMON} autoremove && \
    apt-get ${APT_FLAGS_COMMON} clean && \
    rm -rf /var/lib/apt/lists/*

# bla bla bla copy

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# install python app

# make cron
COPY mycrontab_lines .
RUN chmod 0755
RUN chmod 0644 mycrontab_lines
RUN crontab mycrontab_lines

# start cron service before start blocking application
CMD service cron start && \
    python ./

Build and run container.

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *


Облачная платформа

Fortune cookie: Go out with girls Dutch treat -- pay for dinner, drinks, and the movie, and the rest of the evening is on her.