INT 21h

Hi, I am Vladimir Smagin, SysAdmin. Telegram Email GPG / Микроблог

Cron inside your Docker image with python app

№ 9577 В разделе "Администрирование" от November 25th, 2018,

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

*/5 * * * * /app/cron_script.sh

Now create your cron_script.sh

#!/bin/bash
# load env variables
source /etc/profile
. ~/.profile

python3 /app/mycronapp.py

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 app.py
WORKDIR /app

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

# install python app
COPY app.py .
COPY mycronapp.py .

# make cron
COPY mycrontab_lines .
COPY cron_script.sh .
RUN chmod 0755 run_previewer.sh
RUN chmod 0644 mycrontab_lines
RUN crontab mycrontab_lines

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

Build and run container.

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

Leave a Reply

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

*

Микроблог перейти

# 2018-11-26 09:15:41

Обнаружил в kubedb код google analytics UA-62096468-20, слежка включена по умолчанию.

# 2018-11-24 23:30:12

Несложно смог контейнеризовать nginx unit с предзагрузкой конфигурации перед стартом контейнера blindage.org/?p=9575


© Vladimir Smagin, 2005-2018. Копирование материалов без разрешения запрещено. GPG 0x29AE91B1A37721C3
Яндекс.Метрика

Fortune cookie: God is not dead. He is alive and well and working on a much less ambitious project.